Im supposed to create a program that creates a calculations
Im supposed to create a program that creates a calculations table with addition, subtraction, multiplication, or division. It should ask the user what table they want and the dimensions of the table. I have code that is able to ask the user for these things and I can create successfully create the dimensions of the table but I can\'t seem to get the calculations in the middle of the table. Can someone help me understand how to get the code for the addition part of the code please? Thanks!
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
char choice;
cout << \"Welcome to the math study guide.\" << endl;
cout << \"Which arithemetic table would you like to see?\" << endl;
cout << \"1) Addition\" << endl;
cout << \"2) Subtraction\" << endl;
cout << \"3) Multiplication\" << endl;
cout << \"4) Division\" << endl;
cout << \"X) Exit the program\" << endl;
cin >> choice;
int X,Y,i,j;
cout << \"Enter the dimensions of the table.\ \";
cout << \"Enter X: \";
cin >> X;
cout << \"Enter Y: \";
cin >> Y;
if (X==0 || Y==0)
cout << \"Invalid dimensions\" << endl;
switch (choice)
{
case \'1\': cout << \"You chose Addition.\ \";
for (i=0;i<=X;i++)
cout << i << \" \";
cout<< endl;
for(j=1;j<=Y;j++)
cout << j << endl;
This outputs something like ( for a 5x5 table)
0 1 2 3 4 5
1
2
3
4
5
Solution
#include <iostream>
 #include <iomanip>
 using namespace std;
int main()
 {
 char choice;
 cout << \"Welcome to the math study guide.\ Which arithemetic table would you like to see?\ 1) Addition\ 2) Subtraction\ 3) Multiplication\ 4) Division\ 0) Exit the program\" << endl;
 cin >> choice;
 int X,Y,i,j;
   
 // taking user input
 cout << \"Enter the dimensions of the table.\  Enter X: \";
 cin >> X;
 cout << \" Enter Y: \";
 cin >> Y;
   
 if (X==0 || Y==0)
 cout << \"Invalid dimensions\" << endl;
 else
 switch (choice)
 {
 case \'1\':
 cout << \"You chose Addition.\ \";
// nested loop to print the sum
for (i=0;i<=X;i++)
{
 for(j=0;j<=Y;j++)
 printf(\"%5d\",i+j); // prints sum of ith number and jth number
 cout << endl;
 }
 break;
 case \'2\':
 cout << \"You chose Subtraction.\ \";
 // subtraction part
 break;
 case \'3\':
 cout << \"You chose Multiplication.\ \";
 for (i=1;i<=X;i++)
 {
 for(j=1;j<=Y;j++)
 printf(\"%5d\",i*j);
 cout << endl;
 }
 break;
 case \'4\':
 cout << \"You chose Division.\ \";
 // Division part
 case \'0\':
 cout << \"You chose to exit from the program\";
 }
 }
---------------------------------------------------------------------
You have to use nested loop as mentioned above to get this done
 ---------------------------------------------------------------------
 SAMPLE OUTPUT
Welcome to the math study guide.
Which arithemetic table would you like to see?
1) Addition
2) Subtraction
3) Multiplication
4) Division
0) Exit the program
1
Enter the dimensions of the table.
Enter X: 5
Enter Y: 5
You chose Addition.
0 1 2 3 4 5
1 2 3 4 5 6
2 3 4 5 6 7
3 4 5 6 7 8
4 5 6 7 8 9
5 6 7 8 9 10
---------------------------------------------------------------------
Welcome to the math study guide.
Which arithemetic table would you like to see?
1) Addition
2) Subtraction
3) Multiplication
4) Division
0) Exit the program
3
Enter the dimensions of the table.
Enter X: 4
Enter Y: 4
You chose Multiplication.
1 2 3 4
2 4 6 8
3 6 9 12
4 8 12 16




