I'm afraid what you are attempting to do is probably a bit too advanced for you. You are attempting to dynamically create a multi dimensional array. For this to succeed you're going to first need to understand arrays and pointers or vectors. To start with, when declaring an array, the elements of the array must be a constant variable, which is a variable whose value cannot be changed. For example:
When you are entering text into the forum, on the right side is a format section, click the # symbol and insert your code between the code tags. It formats it nicely and makes it considerably easier to read your code.
use code tags
when you post, look at the tool bar on the right,
click the # in the beginning before you start your code
then push it again when you are finished posting your code.
#include <iostream>
#include <vector>
usingnamespace std;
using std::vector;
int main()
{
vector<vector<char> > grid;
int length;
int hieght;
int L;
int H;
int row;
int collom;
double per;
double w;
double u;
double p;
row = 0;
collom = 0;
cout << "How long do you want your grid? ";
cin >> length;
cout << "How tall do you want your grid? ";
cin >> hieght;
cout << endl;
cout << "What percentage of nodes do you want? ";
cin >> per;
cout << endl;
w = length*hieght;
cout << "Out of " << w << " grid markers, you have ";
u = (per/100);
p = w * u;
int rounded = static_cast<int>(p+.5);
cout << rounded << " nodes." << endl;
hieght = hieght - 1;
length = length - 1;
H = hieght;
grid.resize(hieght);
for (int i = 0; i < hieght; ++i)
grid[i].resize(length);
do
{
L = length;
if( L > -1)
{
grid[H][L] = '*';
cout << grid[H][L];
L = L - 1;
}
H = H - 1;
}
while(H > -1);
cout << endl;
return 0;
}
I'm trying to make a grid where each grid point can be assigned a (x,y) value and changed from a to b at the users will, then some other steps come after that, but I think I can do those pretty easily.
#include <iostream>
#include <vector>
usingnamespace std;
using std::vector;
int main()
{
vector<vector<char> > grid;
int length;
int hieght;
int L;
int H;
int row;
int collom;
double per;
double w;
double u;
double p;
row = 0;
collom = 0;
cout << "How long do you want your grid? ";
cin >> length;
cout << "How tall do you want your grid? ";
cin >> hieght;
cout << endl;
cout << "What percentage of nodes do you want? ";
cin >> per;
cout << endl;
w = length*hieght;
cout << "Out of " << w << " grid markers, you have ";
u = (per/100);
p = w * u;
int rounded = static_cast<int>(p+.5);
cout << rounded << " nodes." << endl;
grid.resize(hieght);
for (int i = 0; i < hieght; ++i)
grid[i].resize(length);
hieght = hieght - 1;
length = length - 1;
H = hieght;
do
{
L = length;
if( L > -1)
{
grid[H][L] = '*';
cout << grid[H][L];
L = L - 1;
}
H = H - 1;
}
while(H > -1);
cout << endl;
return 0;
}