> create a box with 100x100 lines by varying the value of grid.
> I however could create a box with 50x50 when I used grid=50
Yes, the first exercise would be to try it with a box of 5x5
For one thing, you can craft a 5x5 box by hand and post the results here so we have some idea what you're talking about.
And you need to indent your code better.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#include <stdio.h>
#include<stdlib.h>
#include<iostream>
#define grid 100
int i, j;
double dx = 1.0 / (grid); // grid size along x axis.
double dy = 1.0 / (grid); // grid size along y axis
using namespace std;
int main(void)
{
FILE *fP2;
fP2 = fopen("Box(%dx%d).plt", "w");
fprintf(fP2, "VARIABLES=x,y \n");
fprintf(fP2, "ZONE I=%d, J=%d, F=BLOCK, \n\n", grid + 1, grid + 1);
//y node point
for (j = 0; j <= (grid); j++) {
for (i = 0; i <= (grid); i++) {
fprintf(fP2, "%.7lf", j * dx);
fprintf(fP2, "\t");
}
}
fprintf(fP2, "\n\n\n");
// x node point
for (j = 0; j <= (grid); j++) {
for (i = 0; i <= (grid); i++) {
fprintf(fP2, "%.7lf", i * dy);
fprintf(fP2, "\t");
}
}
fprintf(fP2, "\n\n\n");
fclose(fP2);
cout << "calculation is complete!!\n";
system("pause");
return (0);
}
| |
> #define grid 100
It's C++, so
const int grid = 100;
> int i, j;
> double dx = 1.0 / (grid); // grid size along x axis.
> double dy = 1.0 / (grid); // grid size along y axis
There's no reason for these to be global variables.
In fact, your i,j variables should be declared directly in the loops which use them -
for ( int i ...
> fopen("Box(%dx%d).plt", "w");
Were you trying to get a filename called Box(50x50).plt by any chance?