我不知道为什么即使我什么都没输入,“ INVALID INPUT”仍然不断出现?
#include <stdio.h>
#include <ctype.h>
int factorial(long long int b){
if(b<=1){
return 1;
}
else {
return b*factorial(b-1);
}
}
int main()
{
long long int x,am=1;
printf("Lets find the factorial!\n");
while(am==1){
printf("Enter a number: "); scanf("%lld",&x);
printf("Factorial %lld = %lld\n",x,factorial(x));
printf("Try again? Y/N\n");
char con;
while(1){
scanf("%c",&con);
if(toupper(con) == 'Y'){
break;
} else if(toupper(con) == 'N'){
am = 2;
break;
} else {
// this keeps coming out
printf("INVALID INPUT\n");
}
}
}
printf("Thank you for using!\n");
}
稍后再添加此行