附加题:制作简单两个数之间的四则运算

#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)

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Summer_Oranges

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值