Question:
Task 1 - Menu system. (7 points)
The first task is to create a menu system that will drive the program. The user will be able to create an arithmetic table for each of the four basic operators (+,-,*,/). Give the user a menu to choose which of these operators they wish to do.
Example:
Welcome to Math Study guide.
Which arithmetic table would you like to see?
1) Addition
2) Subtraction
3) Multiplication
4) Division
X) Exit the program
>>:
This menu should loop while the user enters invalid responses. The menu loop should stop when the user either enters a value to quit (-1 for example, or a character such as 'X') or a valid input.
Note: You can choose your method of input. If you want to process strings or characters go ahead!
Task 2 - Further input and If-Else If-Else or Switch to handle menu choice (6 points) Now you will get the boundaries for the table.
After getting the menu choice - regardless of which option is chosen you should now get the boundaries for the tables. You will get two numbers since you will be creating an X by Y (2 dimensional) table. Prompt the user for their choices. You should get the input in the format of "x y" (two number with a space in between).
Hint: input doesn't require a prompt to work syntactically, and numerical input reads numbers until it sees any whitespace
If either value is <= 0 tell the user that this is invalid and get the input again.
Example:
Enter the dimensions of the arithmetic table (x y):
Create either an If-Else If-Else chain or use a Switch Statement to handle the menu option.
Create this structure first before filling in the details (part 3).
Task 3 - Generate the appropriate arithmetic table (7 points)
For each math of the math operators generate the appropriate table from 1 to the value provided by the user performing the operator of choice.
You will need to nest your loops to do this properly.
You need to put a header row and column and line up the values accordingly.
So far the code I have:
#include <iostream>
using namespace std;
int main()
{
int input;
int x=0;
int y=0;
//Display Welcome message
cout << "Welcome to the Math Study Guide!";
cout << "Which arithmetic table would you like to see?!";
do
{//displaying the menu
cout << "1 Addition";
cout << "2 Substraction";
cout << "3 Multiplication";
cout << "4 Division";
cout << "X Exit the program";
cout << ">>";
cin >> input;
// if user response is valid:
if (input == '1' || input == '2' || input == '3' || input == '4')
cout <<"Please enter the dimensions (eg: 4 4):";
cin >> x;
cin >> y;
}
// validate the x and y values
while (x <= 0 || y <= 0);
{
cout<< "You have entered an invalid dimension. Please enter a value greater than 0 for both dimensions.";
cout << "Please enter the dimensions of the table (eg: 4 4): ";
cin >> x;
cin >> y;
}
}
switch (input)
{
case '1':
// display the table for addition
System.out.println("\nYou have selected addition with a table size of " + x + " by " + y + ":");
for(double i = 1; i <= x; i++)
{
for(double j = 1; j <= y; j++)
{
cout("%8.2f", (i + j));
}
System.out.println();
}
break;
case '2':
// display the table for subtraction
System.out.println("\nYou have selected subtraction with a table size of " + x + " by " + y + ":");
for(double i = 1; i <= x; i++)
{
for(double j = 1; j <= y; j++)
{
System.out.printf("%8.2f", (i - j));
}
System.out.println();
}
break;
case '3':
// display the table for multiplication
System.out.println("\nYou have selected multiplication with a table size of " + x + " by " + y + ":");
for(double i = 1; i <= x; i++)
{
for(double j = 1; j <= y; j++)
{
System.out.printf("%8.2f", (i * j));
}
System.out.println();
}
break;
case '4':
// display the table for division
System.out.println("\nYou have selected division with a table size of " + x + " by " + y + ":");
for(double i = 1; i <= x; i++)
{
for(double j = 1; j <= y; j++)
{
System.out.printf("%8.2f", (i / j));
}
System.out.println();
}
break;
case 'X':
// display the exit message
System.out.println("Thank you");
break;
default:
// display the error message
System.out.println("That is an invalid selection! Please choose 1-4 or X to exit.");
}
}while(response != 'X');
} // end of main method
} // end of Assignment3 class
#include <iostream>
usingnamespace std;
int main()
{
int input;
int x=0;
int y=0;
//Display Welcome message
cout << "Welcome to the Math Study Guide!";
cout << "Which arithmetic table would you like to see?!";
do
{//displaying the menu
cout << "1 Addition";
cout << "2 Substraction";
cout << "3 Multiplication";
cout << "4 Division";
cout << "X Exit the program";
cout << ">>";
cin >> input;
// if user response is valid:
if (input == '1' || input == '2' || input == '3' || input == '4')
cout <<"Please enter the dimensions (eg: 4 4):";
cin >> x;
cin >> y;
}
// validate the x and y values
while (x <= 0 || y <= 0);
{
cout<< "You have entered an invalid dimension. Please enter a value greater than 0 for both dimensions.";
cout << "Please enter the dimensions of the table (eg: 4 4): ";
cin >> x;
cin >> y;
}
}
switch (input)
{
case'1':
// display the table for addition
System.out.println("\nYou have selected addition with a table size of " + x + " by " + y + ":");
for(double i = 1; i <= x; i++)
{
for(double j = 1; j <= y; j++)
{
cout("%8.2f", (i + j));
}
System.out.println();
}
break;
case'2':
// display the table for subtraction
System.out.println("\nYou have selected subtraction with a table size of " + x + " by " + y + ":");
for(double i = 1; i <= x; i++)
{
for(double j = 1; j <= y; j++)
{
System.out.printf("%8.2f", (i - j));
}
System.out.println();
}
break;
case'3':
// display the table for multiplication
System.out.println("\nYou have selected multiplication with a table size of " + x + " by " + y + ":");
for(double i = 1; i <= x; i++)
{
for(double j = 1; j <= y; j++)
{
System.out.printf("%8.2f", (i * j));
}
System.out.println();
}
break;
case'4':
// display the table for division
System.out.println("\nYou have selected division with a table size of " + x + " by " + y + ":");
for(double i = 1; i <= x; i++)
{
for(double j = 1; j <= y; j++)
{
System.out.printf("%8.2f", (i / j));
}
System.out.println();
}
break;
case'X':
// display the exit message
System.out.println("Thank you");
break;
default:
// display the error message
System.out.println("That is an invalid selection! Please choose 1-4 or X to exit.");
}
}while(response != 'X');
} // end of main method
} // end of Assignment3 class
Do not double post. I left you a response in message http://www.cplusplus.com/forum/beginner/199276/ stick to one thread because it is confusing and hard to follow. Plus it is a waste of time.