hi. i know this program isnt does but i have a question. is there away like after the user clicks lets say 2 to find the factors of a number, but decides he or she wants to use the calculator instead. is there a way i can like let the user enter a number and it will bring them back to the choice of multiplication or multiplication table? - thanks
#include <iostream>
#include <cstdlib>
usingnamespace std;
int main()
{
int choice;
int whatnum;
cout << "here are your options: " << endl << endl;
cout << "1.Calculator" << endl;
cout << "2.Multiplication table" << endl;
cout << endl;
cout << "enter the number before the operation: ";
cin >> choice;
switch(choice){
case 1:
break;
case 2:
cout << "please enter a number you want to find the factors of(up to 12): ";
cin >> whatnum;
}
}
Yes and my suggestion is to wrap what you need in a function. For example:
1 2 3 4 5 6 7 8
initialmenu(){
cout << "here are your options: " << endl << endl;
cout << "1.Calculator" << endl;
cout << "2.Multiplication table" << endl;
cout << endl;
cout << "enter the number before the operation: ";
cin >> choice;
};
Now every time you need the main menu in some context you can call it and bring the user back to the beginning.
The switch is a great idea in this case of a menu so use it but heres the prototype:
1 2 3
function(condition){
case [constant]: //statements to execute if true
}
So your good up until case1 which has no statements which would have been as good as leaving it out. case2 is fine though, i'm assuming you'll add to it later.
yah im going to fill in case 1 later. soon ill try what you told me but i also found another way. the goto loop. its working to go to the menu but how do i make it so like i can press 2 and continue on?
I'm sorry but i dont understand. I compiled it and it seems to work just fine. i press 2 i continue, i press 1 and i go back to the main menu, i pressed 2 and it moves me forward through case 2, i pressed 2 again and it asked for factors which signals its working as you asked. So i dont understand at this point, maybe make it clear what exactly your looking for this program to do.