level 5
// 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分
level 9
对于输入运算符。
你可以在scanf(" %c",&oper)里%c前面加个空格,这是最简单的,或者你可也在scanf()前面加上一句
getchar();
2017年10月17日 00点10分
8
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