Menu Help

Having trouble with this code:


#include <iostream>
using namespace std;

int main()
{
char 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):";
x = cin >> ();
y = cin >> ();

// 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): ";
x = cin >>int();
y = cin >> int();
Use code tags while posting your code, makes it a lot more easier for us to read!

a "do while loop" means that you do;
1
2
3
do {

} while(condition);


x = cin >> (); is not correct syntax as far as I know.
rather
 
cin >> x;


You are also missing an ending bracket for the last 'while' loop, along with a further ending bracket for the int main(){

Don't you have syntax highlighting on your compiler? It helps I think.

Edit: I fixed it if this was what you wanted:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
using namespace std;

int main()
{
char input;
int x=0;
int y=0;
//Display Welcome message
cout << "Welcome to the Math Study Guide!\n";
cout << "Which arithmetic table would you like to see?!\n"; // add newline on end

do
{
cout << "1 Addition\n";
cout << "2 Substraction\n";
cout << "3 Multiplication\n";
cout << "4 Division\n";
cout << "X Exit the program\n";
cout << ">>\n";
cin >> input;

if (input == 'X'){
return 0;
}

}while(!(input == '1' || input == '2' || input == '3' || input == '4'));
// check if the input is valid or not, if it isn't , repeat


while (1){
cout << "Choose x: \n";
cin >> x;
cout << "Choose y: \n";
cin >> y;

if (x <= 0 || y <= 0){
cout << "You have entered an invalid dimension. Please enter a value greater than 0 for both dimensions.\n";
cout << "Please enter the dimensions of the table (eg: 4 4): \n";
}
else{
break; // break out of loop
}
}
} // ending int main () 
Last edited on
You are amazing :)

I have some other issues, if you could help me that would be great. For some reason the code tag isnt working for me but here is the link to the full question!

http://www.cplusplus.com/forum/beginner/199233/
Topic archived. No new replies allowed.