I have to make a grid 40 X 40 with random numbers 0-9. I have already done this and it prints out great. My problem is I need to be able to choose a row number and output the sum of the number in that row. I have no clue how to do this. Here is what I have so far. Can anyone help??
#include <iostream>
usingnamespace std;
int main()
{
int Values[40][40];
int rows, cols;
for(rows = 0; rows<40; rows++)
for (cols = 0; cols<40; cols++)
Values[rows][cols] = rand () % 10;
for(rows = 0; rows<=39; rows++)
{
cout<<'\n';
for (cols = 0; cols<=39; cols++)
{
cout<<Values[rows][cols];
cout<<" ";
}
}
int R, C;
cout<<"\n Which row (0-39) would you like to sum?\n";
cin>> R;
cout<<'\n';
cout<<"The sum of the numbers in row "<<R<<" is "<<C;
system ("pause");
}
int R, C;
do
{
cout<<"\n Which row (0-39) would you like to sum?\n";
cin>> R;
cout<<'\n';
int sum = 0;
for (cols = 0; cols<40; cols++)
sum += Values[R][cols];
cout<<"The sum of the numbers in row "<< R<<" is "<< sum << endl;
} while (R!=0);
return 0;
}
PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/