基于C++的四则运算器

时间:2022-01-16 20:41:06

      四则运算器分为加,减,乘,除.该程序引用persistence_s博客的内容,地址:http://blog.csdn.net/persistence_s/article/details/70983787.

  Github地址:https://github.com/Divel-Qin/C-Program/tree/master/Four%20arithmetic%20calculators

   大概花了半天时间才看懂该程序,该程序是用C++写的,有控制台命令行,没有图形界面,利用了栈先进后出的原理,完成该程序.我用他的代码在Visual Studio 2017上运行报了很多错,不知道是不是自己配置的环境错误还是他的程序出错,通过百度改也改不出来,然后再用Visual Studio 2017连接github上传CPP文件.

  加法主要函数:

void add()
{
printf("输入要计算的加数(例如a b)\n");
int adda = 0, addb = 0, addc = 0;
cin >> adda;
cin >> addb;
addc = adda + addb;
cout << adda << "加" << addb << "等于" << addc << endl;
}

  减法主要函数:

void substraction()
{
printf("输入要计算的减数(例如a b)\n");
int suba = 0, subb = 0, subc = 0;
cin >> suba;
cin >> subb;
subc = suba - subb;
cout << suba << "减" << subb << "等于" << subc << endl;
}

  乘法主要函数:

void multiplication()
{
printf("输入要计算的乘数(例如a b)\n");
int mula = 0, mulb = 0, mulc = 0;
cin >> mula;
cin >> mulb;
mulc = mula*mulb;
cout << mula << "乘" << mulb << "等于" << mulc << endl;

}

  除法主要函数:

void division()
{
printf("输入要计算的除数(例如a b)\n");
int dsa = 0, dsb = 0, dsc = 0, dsd = 0;
cin >> dsa;
cin >> dsb;
dsc = dsa / dsb;
dsd = dsa%dsb;
cout << dsa << "除" << dsb << "等于" << dsc << "余" << dsd << endl;
}