运行结果键入运算符键入不了,之后就无法继续了
c4droid吧
全部回复
仅看楼主
level 5
Tenjoy_Chio 楼主
运行结果键入运算符键入不了,之后就无法继续了[小红脸] [小红脸] [小红脸]
2017年10月16日 23点10分 1
level 5
Tenjoy_Chio 楼主
求解啊[泪][泪][泪]
2017年10月17日 00点10分 2
level 9
源码,发出嘛😊
2017年10月17日 00点10分 3
4楼
2017年10月17日 00点10分
level 5
Tenjoy_Chio 楼主
// Simple calculator implementation
//
#include"stdio.h"
int main()
{
int line;
double n, m;
char oper;
printf("\t******Simple calculator******\n");
for (line=0 ; line<=51 ; line++)
{
printf("-");
}
printf("\nPlease input a number: ");
scanf("%f",&n);
printf("Please input another number: ");
scanf("%f",&m);
printf("Please choice the oper you want to calculate: \n");
printf(" \t +\t -\t *\t / \n");
for (line=0 ; line<=51 ; line++)
{
printf("-");
}
printf("\n");
/*
scanf("%c",&oper);
if (oper=='+')
printf("Addition result: %f",n+m);
else if (oper=='-')
printf("Subtraction result: %f",n-m);
else if (oper=='*')
printf("Multiplication result: %f",n*m);
else if (oper=='/')
if (m==0)
printf("Error!The divisor can not be \"0\".\n");
else
printf("Division result: %f",n/m);
else return 0;
*/
scanf("%c",&oper);
switch (oper)
{
case '+': printf("%f",n+m);break;
case '-': printf("%f",n-m);break;
case '*': printf("%f",n*m);break;
case '/':
{
if(m==0) printf("Erro!The divisorcan not be \"0\"\n");
else
{
printf("%f",n/m);break;
}
}
printf("End!\n");
return 0;
}
}
2017年10月17日 00点10分 4
level 9
double 是双精度,用printf("%lf",%n);
或者改成float。
2017年10月17日 00点10分 5
level 14
给double输入值要用%lf
printf的时候如果出现%lf,后面有没有相应的变量参数 就改成 %%lf
scanf有可能会获取到空白符号比如空格或者回车,你把这些情况排除就可以了。
2017年10月17日 00点10分 6
我看到了,是获取了空格,如何取消呢?
2017年10月17日 00点10分
@Tenjoy_Chio 循环重新获取呗
2017年10月17日 01点10分
level 14
2017年10月17日 00点10分 7
level 9
对于输入运算符。
你可以在scanf(" %c",&oper)里%c前面加个空格,这是最简单的,或者你可也在scanf()前面加上一句
getchar();
2017年10月17日 00点10分 8
level 10
8L+1
2017年10月17日 01点10分 9
level 1
// Simple calculator implementation
//
#include"stdio.h"
int main()
{
int line;
double n, m;
char oper;
printf("\t******Simple calculator******\n");
for (line=0 ; line<=51 ; line++)
{
printf("-");
}
printf("\nPlease input a number: ");
scanf("%f",&n);
printf("Please input another number: ");
scanf("%f",&m);
printf("Please choice the oper you want to calculate: \n");
printf(" \t +\t -\t *\t / \n");
for (line=0 ; line<=51 ; line++)
{
printf("-");
}
printf("\n");
/*
scanf("%c",&oper);
if (oper=='+')
printf("Addition result: %f",n+m);
else if (oper=='-')
printf("Subtraction result: %f",n-m);
else if (oper=='*')
printf("Multiplication result: %f",n*m);
else if (oper=='/')
if (m==0)
printf("Error!The divisor can not be \"0\".\n");
else
printf("Division result: %f",n/m);
else return 0;
*/
scanf("%c",&oper);
switch (oper)
{
case '+': printf("%f",n+m);break;
case '-': printf("%f",n-m);break;
case '*': printf("%f",n*m);break;
case '/':
{
if(m==0) printf("Erro!The divisorcan not be \"0\"\n");
else
{
printf("%f",n/m);break;
}
}
printf("End!\n");
return 0;
}
}
2017年10月17日 14点10分 10
1