I'm trying to make a very basic program that is supposed to mimic a tv of sorts, its supposed to be for learning switch statements, and i am supposed to do it within a while loop. Here is what i have.
Code:
#include <stdio.h>
int chan = 5, i = 4;
char rem;
int main (int argc, char * const argv[]) {
while (i){
printf("\nCurrent channel: %d", chan);
printf("\nUse your remote (e,p,s,m,c):");
scanf("%c",&rem);
switch (rem){
case 'e':
return 0;
break;
case 'm':
printf("Muted");
getchar();
break;
case 'p':
printf("Playing");
getchar();
break;
case 's':
printf("Stopping");
getchar();
break;
case 'c':
printf("\nEnter Desired Channel: ");
scanf("%d",&chan);
break;
}
}
return 0;
}
My problem seems to be that it skips the scanf within the loop everytime i write to the variable chan. Any ideas why? I realize i need a default but that didn't seem to fix anything, and will be added.