怎样用C++编写一个简单的计算器

怎样用C++编写一个简单的带加减乘除的带外观的计算器,代码尽量简单些,麻烦知道的朋友告诉下,顺便写下源代码,先多谢了!!!

第1个回答  2013-09-10
#include<stdio.h>
void main()/*只能算一些简单的+ - * / %*/
{
double number1=0.0;
double number2=0.0;
char operation=0;
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\aPivision by zero error!\n");
else
printf("=%lf\n",number1/number2);
break;
case'%':
if((long)number2==0)
printf("\n\n\a Division by zero error!\n");
else
printf("=%ld\n",(long)number1/(long)number2);
break;
default:
printf("\n\n\aIllegal operation!\n");
}

}
第2个回答  2017-07-25
明确需求,平台环境Windows还是linux是不是需要图形界面。
第3个回答  2013-09-10
#include<stdio.h>
#include<math.h>
main()
{
float a,b;
char c;
printf("shurushuzihefuhao:");
scanf("%f%c%f",&a,&c,&b);
if (c="+")
printf("%f",a+b);
else if (c="-")
printf("%f",a-b);
else if (c="*")
printf("%f",a*b);
else if (c="/")
printf("%f",a/b);
getch();
}
相似回答