C语言中scanf被跳过-求大神解决

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_29220631/article/details/51832119

这段程序在vc++6.0中编译组建都没有问题,可是运行后发现里面有一段代码被跳过了,如何解决?

# include<stdio.h>

int main(void)
{
double number1, number2;
char operation;
char answer;

start:
printf("\nEnter the calculation\n");
scanf("%lf %c %lf", &number1,&operation,&number2);

switch(operation)
{
case '+':
printf("=%lf\n", number1 + number2);
break;
case '-':
printf("=%lf\n", number1 - number2);
break;
case '*':
printf("=%lf\n", number1 * number2);
break;
case '/':
if(number2 == 0)
printf("\n\n\aDivision by zero error\n");
else
printf("=%lf\n", number1 / number2);
break;
case '%':
if((long)number2 == 0)
printf("\n\n\aDivision by zero error\n");
else
printf("=%lf\n", (long)number1 % (long)number2);
break;
default:
printf("\n\n\aIllegal operation!\n");
break;
}

printf("Do you want to do another calculation?(y or n):\n");
scanf("%c",&answer);
if(answer == 'y' || answer == 'Y')
goto start;

return 0;
}


运行后是这样的




请问如何解决

阅读更多

没有更多推荐了,返回首页