Switch / Case

Please see: https://www.tutorialspoint.com/cprogramming/switch_statement_in_c.htm

    switch (Variable){
         case X: ....
                 break;
         case Y: ....
                 break;
         case Z: .....
                 break;
         default: ....
                 break;
    }

Example with if conditional:


#include <cstdlib>
#include <stdio.h>
using namespace std;

int main(int argc, char** argv) {
    char ThisIsAVariable;

    printf("Type A, B, or C: ");
    scanf("%c",&ThisIsAVariable);

    if(ThisIsAVariable=='A'){

        printf("You Typed A\n");

    }else{

        if(ThisIsAVariable=='B'){

            printf("You Typed B\n");

        }else{

            if(ThisIsAVariable=='C'){

                printf("You Typed C\n");

            }else{

                printf("You Didn't do as I asked!\n");

            }
        }
    }
    return (0);
            
}

Example using case statement:


#include <cstdlib>
#include <stdio.h>
using namespace std;

int main(int argc, char** argv) {

    char ThisIsAVariable;

    printf("Type A, B, or C: ");
    scanf("%c",&ThisIsAVariable);

    switch (ThisIsAVariable){
        case 'A':
            printf("You Typed A\n");
            break;
        case 'B':
            printf("You Typed B\n");
            break;
        case 'C':
                printf("You Typed C\n");
                break;
        default:
                printf("You Didn't do as I asked!\n");
                break;
    }
            
    return (0);
}