C++编写一个加减乘除开方乘方计算器

#include<iostream>
#include<cmath>
using namespace std;
void Addition(double a,double b)
{
    cout<<a+b<<endl;
}
void Subtraction(double a,double b)
{
    if(a>b)
        cout<<a-b<<endl;
    else
        cout<<"-"<<b-a<<endl;
}
void Multiplication(double a,double b)
{
          cout<<a*b<<endl;
}
void Division(double a,double b)
{
          cout<<a/b<<endl;
}
void Root(double a)
{
    cout<<sqrt(a)<<endl;
}
void Involution(double a,double b)
{
          cout<< pow(a,b)<<endl;
}
int main()
{
    int x;
    double a = 0.0,b = 0.0;
    cout<<"0代表加法\n"<<"1代表减法\n"<<"2代表乘法\n"<<"3代表除法\n"<<"4代表根号\n"<<"5代表平方\n"<<"6代表退出计算\n"<<endl;
    cout<<"请输入计算方式的代号:\t";
    cin>>x;
    
    cout<<"已为您转入计算空间"<<x<<"."<<endl;
    do
    {
        switch(x)
        {
            case 0:
            {
                cout<<"请输入:\t";
                cin>>a>>b;
                Addition(a,b);
                break;
            }
            case 1:
            {
                cout<<"请输入:\t";
                cin>>a>>b;
                Subtraction(a,b);
                break;
            }
            case 2:
            {
                cout<<"请输入:\t";
                cin>>a>>b;
                Multiplication(a,b);
                break;
            }
            case 3:
            {
                cout<<"请输入:\t";
                cin>>a>>b;
                Division(a,b);
                break;
            }
            case 4:
            {
                cout<<"请输入:\t";
                cin>>a;
                Root(a);
                break;
            }
            case 5:
            {
                cout<<"请输入:\t";
                cin>>a>>b;
                Involution(a,b);
                break;
            }
            case 6:
                break;
        }
    }
    while(x);
}


在这里插入图片描述
上面这幅图展示的是乘方运行结果。

展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 深蓝海洋 设计师: CSDN官方博客
应支付0元
点击重新获取
扫码支付

支付成功即可阅读