Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Switch Statement Problem (http://www.go4expert.com/forums/switch-statement-problem-t27124/)

amplechin 9Nov2011 21:53

Switch Statement Problem
 
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.

xpi0t0s 10Nov2011 17:14

Re: Switch Statement Problem
 
Code:

printf("[display menu]");
char buf[32];
fgets(buf,30,stdin);
switch (atoi(buf))
{
case 1: /* do the 1 stuff */ break;
case 2: /* do the 2 stuff */ break;
case 3: /* do the 3 stuff */ break;
default: printf("INVALID\n"); break;
}



All times are GMT +5.5. The time now is 15:00.