mardi 18 février 2020

Convert the following switch statement into if with two alternatives statement

Two alternatives

I know how to convert this into multiple alternative if statement. But my problem is how do I convert it to a if statement with only two alternatives.

#include <stdio.h>

int main (void)
{
    int a;
    char option ;
    printf ( "Choose your option : ") ;
    scanf ( "%c",&option ) ;
    switch(option)
    {
    case 'a':
    case 'A':
        a=20+10;
        printf("Addition process result: %d", a ) ;
        break ;
    case 'b':
    case 'B':
        a = 20 - 10;
        printf("Subtraction process result: %d", a ) ;
        break ;
    case 'c':
    case 'C':
        a =20*10;
        printf("Multiplication process result: %d" , a ) ;
        break ;
    case 'd':
    case 'D':
        a =20/10;
        printf("Division process result: %d" , a ) ;
        break ;
    default: printf ("Invalid option") ;
    }

    return 0;
}

Aucun commentaire:

Enregistrer un commentaire