新手求教,编写一个简单计算器,支持+,-,*,/,%运算,有什么问题,运行不出来
/*Program a calculator*/#include<stdio.h>
int main(void)
{
double number1 = 0.0; /*First operand value a decimal number*/
double number2 = 0.0; /*First operand value a decimal number*/
char operation = 0; /*Operation - must be +,-,*,/,or % */
printf("\nEnter the calculation\n");
scanf_s("%lf %c %lf",&number1,&operation,&number2);
/*Code to check the opration is valid*/
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("= %ld\n", (long)number1 % (long)number2);
}
break;
default:
printf("\n\n\aIllegal operation!\n");
break;
}
return 0;
}