用c++写的一个简单的计算器程序,,,,,
发布时间:2020-12-16 07:42:19 所属栏目:百科 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 系统:win7 电脑:dell 运行环境:vs2015 语言:c++ //四则运算#include "stdafx.h"#includeiostream#includestdio.husing namespace std;void add(){
以下代码由PHP站长网 52php.cn收集自互联网 现在PHP站长网小编把它分享给大家,仅供参考 系统:win7电脑:dell 运行环境:vs2015 语言:c++ //四则运算 #include "stdafx.h" #include<iostream> #include<stdio.h> using namespace std; 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; } void operation()//运算函数 { printf("输入数据选择做那种运算n"); printf("输入0选择退出,1做加法,2做减法,3做乘法,4做除法(保留余数)n"); int operatione = 0; cin >> operatione; cout << endl; try { if (operatione == 1) { //加法 add(); } else if (operatione == 2) { //减法 substraction(); } else if (operatione == 3) { //乘法 multiplication(); } else if (operatione == 4) { //出发 division(); } else if (operatione == 0) { exit(0); } else { throw 1; } } catch (int i) { cout << "输入错误" << endl; } operation(); } int main() { printf("欢迎使用本计算器"); operation(); return 0; } //技术交流[email?protected] //邮箱[email?protected] //欢迎在我博客或者邮箱留言,交流!技术交流!!! 以上内容由PHP站长网【52php.cn】收集整理供大家参考研究 如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |