I need to write a program that sums all values in an array row that the user can choose. The program sums correctly but instead of only outputting one row's sum, it sums up all of the rows up until the input row and adds them all together. I can't figure out whats wrong with it.
Thanks in advance
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std
;
int main()
{
srand(time(0));
int values[40][40]={0};
int rows, columns;
int alpha[] = {1,2,3,4,5,6,7,8,9};
for (rows = 0;rows<40;rows++)
{
for(columns=0;columns<40;columns++)
{
values[rows][columns] = alpha[rand()%9];
cout<<" "<<values[rows][columns];
}
cout<<endl;
}
int sumnumber,j,answer=0;
cout<<"Which row would you like to sum? (0-39)\n"; cin>>sumnumber;
for(rows = 0; rows < sumnumber; rows++)
{
for(columns=0;columns<40;columns++)
{
answer += values[rows][columns];
}
}
cout<<answer;
}