OJ期终刷题 Problem I: C/C++经典程序训练3-模拟计算器

OJ期末刷题 Problem I: C/C++经典程序训练3---模拟计算器

Description

简单计算器模拟:输入两个整数和一个运算符,输出运算结果;

Input

第一行输入两个整数; 第二行输入一个运算符(+、-、*、/);

Output

输出对两个数运算后的结果;

Sample Input

30 50
*

Sample Output

1500

代码:

#include <iostream>

using namespace std;

int main()
{
    int a,b;
    double c;
    char d;
    cin>>a>>b;
    cin>>d;
    switch (d)
    {

    case '+':
        c=a+b;
        break;
    case '-':
        c=a-b;
        break;
    case '*':
        c=a*b;
        break;
    case '/':
        c=a/b;
        break;
    }
    cout<<c;
    return 0;
}

运行结果:


OJ期终刷题 Problem I: C/C++经典程序训练3-模拟计算器


学习心得:

好好学习 天天向上