int main()
{
int program = 0;
while (program >= 0)
{
printf("\nChoose one of the following programs: \n\n (1) Fibonacci Sequence Calculator \n (2) Decimal and Binary Calculator \n (3) Prime Number Calculator \n \nIf you want to exit the program, press (e).\nYour choice: ");
scanf("%d", &program);
if (program == 0)
{
printf("Quitting the program...\n\n");
return 0;
}
else if(program==1)
{
printf ("FIBONACCI SEQUENCE CALCULATOR");
}
else if(program==2)
{
printf("DECIMAL AND BINARY CALCULATOR");
}
else if(program==3)
{
printf("PRIME NUMBER CALCULATOR");
}
else
{
printf("ERROR");
}
}
I want to print "ERROR" when the user input anything except 0,1,2 and 3, but this is the result when I input:
- any number except 0,1,2,and 3: "ERROR" (this is correct)
- any letter/symbol: "Quitting the program..."(this should be "ERROR"!)
Maybe this can help me to figure out the answer to my problem: What I've already know that %d is for scanning the integer and %c for scanning the character. But what do I have to use when I want to scan both of them?
Any help would be appreciated :)