help

Discussion in 'Meet and Greet' started by chan_chan, Nov 28, 2011.

  1. chan_chan

    chan_chan New Member

    Joined:
    Nov 28, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    write a program that asks a user an integer, prompt a menu that says:
    a=addition
    b=subtraction
    c=multiplication
    d=division
    and return the given option.
     
  2. KRV

    KRV New Member

    Joined:
    Dec 26, 2011
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    LEARNING
    Location:
    SRI LANKA
    Code:
    #include <stdio.h>
    //not exactly what you asked but will help ya
    int main (void)
    {
          float value1, value2;
          char operator;
    
          printf("Type in your expression.\n");
          scanf("%f %c %f", &value1, &operator, &value2);
          switch (operator)
    {
         case '+':
         printf ("%.2f\n", value1 + value2);
    
         break;
         case '-':
    
         printf ("%.2f\n", value1 - value2);
         break;
         case '*':
         printf ("%.2f\n", value1 * value2);
         break;
         case '/':
        if ( value2 == 0 )
        printf ("Division by zero.\n");
        else
        printf ("%.2f\n", value1 / value2);
        break;
        default:
        printf ("Unknown operator.\n");
        break;
        }
        return 0;
    }
     

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