Hi so I've created a simple calculator and in my scanf() function what can i do so that if nothing is entered by the user ( or if the user inputs the Enter
key ) I want the program to end.
#include<stdio.h>
int main(){
int a, b;
char choice;
while(1){
printf("Enter your input: ");
scanf("%d %c %d", &a, &choice, &b);
switch(choice){
case '+':
printf("%d %c %d = %d", a, choice, b, a+b);
break;
case '-':
printf("%d %c %d = %d", a, choice, b, a-b);
break;
case '*':
printf("%d %c %d = %d", a, choice, b, a*b);
break;
case '/':
printf("%d %c %d = %d", a, choice, b, a/b);
break;
default:
printf("Error calculating! Exiting.\n");
return 0;
break;
}
printf("\n");
}
return 0;
}