This simple program has a switch statament that is supposed to go to "default" only if the user doesn't follow the rules. But it goes to "default" anyway after the first run. I cannot explain why.
#include <stdio.h>
#include <windows.h>
int main(){
char a = 'a'; //I tried to put 'n' here, but it goes to default anyway.
while (TRUE){
printf("Type \'n\' for notepad, \'e\' for explorer or \'g\' for both (type \'p\' to exit): ");
scanf("%c", &a);
switch (a){
case 'n':
system("notepad"); break;
case 'e':
system("explorer"); break;
case 'g':
system("notepad & explorer"); break;
case 'p':
return 0;
default:
printf("Something went wrong. Read the instructions carefully.\n");
}
}
return 0;
}