Using switch statement, how can i create a program that ask the user to enter choices 1,2 or 3 only and do the problem below?
SAMPLE OUTPUT
*********CHOICES*********
[1] number to roman
[2] 12hour to 24hour clock
[3] exit
*************************
ENTER YOUR CHOICE:4
INVALID.
(Terminated)
ENTER YOUR CHOICE:1
[1] Conversion
Create a program that prompts the user to enter a number (from 1-3000 only) then output the number and its corresponding roman numeral number.
[2] 12Hr clock 24Hr clock
Create a program that will prompt the user to input time based on a 12-hour clock and output the corresponding time based on a 24-hour clock. Check all possible invalid input data.
Simple switch statements are easy enough to write. Have you written any code or are you asking actually how to write the code for this?
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
int x;
cout << "Enter some number: ";
cin >> x;
cout << endl;
switch(x){ // x is the variable you wish to test
case 1: // this is the first case you wish to test, such as an int, string, etc.
// cont.. the instance you would want to test would replace the 1 or the 2, such as
// cont.. a string, char, int, double, bool, long, etc.
// so it would look like this -- case 'a' -- or -- case "hello" -- or -- case 23
//code you wish to execute if case 1 is true
break;
case 2: //if you have a second case then it would be here
// code to execute here.
break;
default: // if neither of these cases are true then it would do this.
}
Edit: This is only a shell. If you actually want to execute code for this then you will have to fill in all of the blanks. If you have any problems just go ahead and ask.