Switch Statement Problem

Discussion in 'C' started by amplechin, Nov 9, 2011.

  1. amplechin

    amplechin New Member

    Joined:
    Nov 9, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    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;
    }
    
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice