#include <iostream> //引用iostream文件(用于调用cout与cin)
#include <cstdio> //引用cstdio文件(用于调用printf函数)
using namespace std; //命名空间std
void main() //使用无类型主函数
{ //函数体
double a, b, c;
printf("Please input a number to a\n");
cin >> a;
printf("Please input a number to b\n");
cin >> b; //为双精度数a,b赋值
cout << "Please choose a four arithmetic operation" << endl;
printf("'+' means to add\n");
printf("'-' means to reduce\n");
printf("'*' means to division\n");
printf("'/' means to division\n"); //输出选择运算的文本
char d;
char e='+';
char f='-';
char g='*'; //定义字符类型d,e,f,g,其中d为选择运算用字符串
cin >> d;
if (d == e) //以下为判断为何种运算
{
cout << a + b;
}
else if (d == f)
{
cout << a - b;
}
else if (d == g)
{
cout << a * b;
}
else
{
cout << a / b;
}
//程序结束
}
实际效果:
1:启动程序
2:为a赋值(这里赋值为123)
3:为b赋值(这里赋值为345)
4:选择为何种四则运算(这里选择了*,即为乘法),并输出结果(此处结果为42435)