jeudi 8 novembre 2018

Turn Switch statement into if/then and if/else statement

I want to make this switch statement into if/else and if/then statement. My Switch statement is :

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");
    }

Aucun commentaire:

Enregistrer un commentaire