The purpose of the following code is to get a random number of 100 nodes and to distribute these nodes randomly in range 500*500 …(X,Y).. this was the first step

#include<iostream>  
#include <fstream>  
#include<cmath>  

using namespace std;  

int  main()   
{  
 const int x = 0, y = 1;   
 int nodes[100][2];    
 ofstream myfile;  
 myfile.open ("example.txt");     
 myfile << "Writing this to a file.\n";  

 for (int i=0; i<100 ;i++)  
 {     
      nodes[i][x] = rand() % 501;    
      nodes[i][y] = rand() % 501;  
      myfile <<nodes[i][x]<<" "<<nodes[i][y];  
 }

 myfile.close();
}

the next step is to divide the the x and y axis will be divided in to 55 , so I will have 25 grids
Starting the axis from 0-99-199-299 until 499 ,what I’m trying to do is to distribute 4 nodes in each “100
100” grid
I try to do it by rewrite the code, but I get an error and I could not understand it

"IntelliSense: expression preceding parentheses of apparent call must have (pointer-to-) function type"
how can i fix it

#include <iostream>  
#include <fstream>  
#include <cmath>  

 using namespace std;  



 int  main()   

 {  
     ofstream myfile;  
    myfile.open ("example.txt");  
    myfile << "Writing this to a file.\n"; 


 int miny=0,max_y=99;
for(int i=0;i<5;i++)
{
    int minx=0,max_x=99;
for(int j=0;j<5;j++)
{
    for(int k=0;k<=4;k++)
    {
    int     x=(minx+rand()*10(max_x +1)%(max_x - minx+1));
    int     y=(miny+rand()*10(max_y +1)%(max_y - miny+1));
    }
    minx=max_x+1;
    max_x=max_x+100;
}
miny=max_y+1;
max_y=max_y+100;
}


 }

Dani AI

Generated

The IntelliSense error happens because an expression like rand()*10(max_x +1) is parsed as a function call: a literal or value followed immediately by parentheses. That is a syntax error. The intent can be expressed simply as an arithmetic expression or by using the usual range formula. For example, with rand() the correct one‑line way to get an integer in [min, max] is:

x = min + rand() % (max - min + 1);

However, rand() + % has bias and requires a single srand(...) seed call (not inside loops). A more robust, modern approach is to use <random> (C++11+) and generate offsets inside each 100x100 cell. The algorithm is: loop grid Y = 0..4 and X = 0..4, compute cell origin as (X100, Y100), then generate 4 points per cell with offsets in [0,99] and add the origin. That produces 25 cells * 4 points = 100 points distributed across 0..499.

A compact, safe implementation using <random>:

#include <fstream>
#include <random>

int main() {
    std::random_device rd;
    std::mt19937 gen(rd());
    std::uniform_int_distribution<int> off(0, 99); // offset within a 100x100 cell

    std::ofstream out("example.txt");
    for (int gy = 0; gy < 5; ++gy) {
        for (int gx = 0; gx < 5; ++gx) {
            int ox = gx * 100, oy = gy * 100;
            for (int i = 0; i < 4; ++i) {
                int x = ox + off(gen);
                int y = oy + off(gen);
                out << x << ' ' << y << '\n';
            }
        }
    }
}

Notes: seed the generator once, not per point; ensure the distribution bounds match the cell size (0..99) so global max is 499; compile with C++11 or later. This addresses the syntax error and gives a cleaner, more predictable random distribution than manipulating rand() inside nested loops. explained the goal clearly; the change above resolves the parse error and achieves the desired 5x5 grid with 4 random points per cell.

i want to fill 5x5 contiguous 2D cells of size 100x100 each with 4 random points.

T

Every cell will be processed independently, using a double loop on X and Y (from 0 to 500 excluded, step 100).

For each cell, generate 4 random points with coordinates in the range 100x100 (i.e. the cell size).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.