PROBLEM STATEMENT: Replicate the following user interaction. You have a 5 by 5 b
ID: 3677938 • Letter: P
Question
PROBLEM STATEMENT: Replicate the following user interaction. You have a 5 by 5 board. Enter numbers in cells and add up each row and total the rows as shown. User input is shown in red. You must store the board information in a 2 dimensional array.
Example run 1:
0 0 0 0 0 = 0
0 0 0 0 0 = 0
0 0 0 0 0 = 0
0 0 0 0 0 = 0
0 0 0 0 0 = 0
TOTAL: 0
Continue (Y/N)? Y
Enter row: 0
Enter column: 0
Enter value: 5
5 0 0 0 0 = 5
0 0 0 0 0 = 0
0 0 0 0 0 = 0
0 0 0 0 0 = 0
0 0 0 0 0 = 0
TOTAL: 5
Continue (Y/N)? Y
Enter row: 1
Enter column: 1
Enter value: 8
5 0 0 0 0 = 5
0 8 0 0 0 = 8
0 0 0 0 0 = 0
0 0 0 0 0 = 0
0 0 0 0 0 = 0
TOTAL: 13
Continue (Y/N)? Y
Enter row: 1
Enter column: 4
Enter value: 9
5 0 0 0 0 = 5
0 8 0 0 9 = 17
0 0 0 0 0 = 0
0 0 0 0 0 = 0
0 0 0 0 0 = 0
TOTAL: 22
Continue (Y/N)? N
MORE EXAMPLES BELOW!
Example run 2:
0 0 0 0 0 = 0
0 0 0 0 0 = 0
0 0 0 0 0 = 0
0 0 0 0 0 = 0
0 0 0 0 0 = 0
TOTAL: 0
Continue (Y/N)? Y
Enter row: 0
Enter column: 0
Enter value: 1
1 0 0 0 0 = 1
0 0 0 0 0 = 0
0 0 0 0 0 = 0
0 0 0 0 0 = 0
0 0 0 0 0 = 0
TOTAL: 1
Continue (Y/N)? Y
Enter row: 1
Enter column: 1
Enter value: 2
1 0 0 0 0 = 1
0 2 0 0 0 = 2
0 0 0 0 0 = 0
0 0 0 0 0 = 0
0 0 0 0 0 = 0
TOTAL: 3
Continue (Y/N)? Y
Enter row: 2
Enter column: 2
Enter value: 3
1 0 0 0 0 = 1
0 2 0 0 0 = 2
0 0 3 0 0 = 3
0 0 0 0 0 = 0
0 0 0 0 0 = 0
TOTAL: 6
Continue (Y/N)? Y
THIS EXAMPLE CONTINUES BELOW!
Enter row: 3
Enter column: 3
Enter value: 4
1 0 0 0 0 = 1
0 2 0 0 0 = 2
0 0 3 0 0 = 3
0 0 0 4 0 = 4
0 0 0 0 0 = 0
TOTAL: 10
Continue (Y/N)? Y
Enter row: 4
Enter column: 4
Enter value: 5
1 0 0 0 0 = 1
0 2 0 0 0 = 2
0 0 3 0 0 = 3
0 0 0 4 0 = 4
0 0 0 0 5 = 5
TOTAL: 15
Continue (Y/N)? N
Example run 3:
0 0 0 0 0 = 0
0 0 0 0 0 = 0
0 0 0 0 0 = 0
0 0 0 0 0 = 0
0 0 0 0 0 = 0
TOTAL: 0
Continue (Y/N)? N
Explanation / Answer
#include<iostream.h>
#include<conio.h>
int main()
{
int square[5][5];
int i,j;
int sum=0;
int total=0;
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
square[i][j]=0;
cout<<square[i][j];
}
}
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
sum= sum+square[i][j];
}
cout<<"="<<sum;
total=total+sum;
sum=0;
}
cout<<"="<<total;
cout<<"Continue:y/n?";
char choice;
cin>>choice;
if(choice == 'y')
{
cout<<"enter the row:";
cin>>row;
cout<<"enter the column:";
cin>>column;
cout<<"enter the value";
cin>>value;
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(i== row && j== column)
square[i][j]=value;
}
}
int sum=0;
int total=0;
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
cout<<square[i][j];
}
}
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
sum= sum+square[i][j];
}
cout<<"="<<sum;
total=total+sum;
sum=0;
}
}
else
if(choice=='n')
break; // or Exit;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.