I want the program to terminate as soon as the user enters a letter which isn't 'A' or 'B'. Is it possible to only print the default case for input 1 even if the user enters 'A' or 'B' for input 2? I tried the exit() function from stdlib.h but I can't seem to find a placement in the code that would work. I understand that a nested switch statement could also work but the full program takes in 8 inputs and I'd have to nest 8 times
So for example: Enter a value: C Enter a value: A Invalid letter for first input! Terminating program...
#include <stdio.h>
int main()
{
char input1;
printf("Enter a value: ");
scanf(" %c", &input1);
char input2;
printf("Enter a value: ");
scanf(" %c", &input 2);
char A = 'A';
char B = 'B';
switch(input1){
case 'A':
printf("Your letter is A");
break;
case 'B':
printf("Your letter is B");
break;
default:
printf("Invalid letter for first input! Terminating program...");
break;
}
switch(input2){
case 'A':
printf("First letter of the alphabet");
break;
case 'B':
printf("Second letter of the alphabet");
break;
default:
printf("Invalid letter for second input! Terminating program...")
break;
}
return 0;
}