C/C++

推荐列表 站点导航

当前位置:首页 > 脚本编程 > C/C++ >

C++_c++编写简单的计算器程序,首先来看下本人的开发环境

来源:网络整理  作者:fen  发布时间:2020-12-25 07:19
c++编写简单的计算器程序,首先来看下本人的开发环境系统:win7电脑:dell运行环境:vs2015语言:c++简单计算器代码/...

首先来看下本人的开发环境

系统: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 = mulaIT之家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; }

代码比较简单,希望大家能够喜欢

相关热词: C++

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!

本文地址: https://v30.fanwenzhu.com/jiaob/cjj/8830.shtml

最新文章
只需要在调用Ctrl+B编译后 只需要在调用Ctrl+B编译后

时间:2021-01-13

OpenGL超级宝典visual studio OpenGL超级宝典visual studio

时间:2021-01-04

Directx11 教程(2) 基本的wi Directx11 教程(2) 基本的wi

时间:2021-01-04

LeetCode11ContainerWithMostWate LeetCode11ContainerWithMostWate

时间:2021-01-04

C语言简单IT之家速成 C语言简单IT之家速成

时间:2020-12-27

三分钟了解Activity工作流 三分钟了解Activity工作流

时间:2020-12-27

编译器是如何实现32位整型 编译器是如何实现32位整型

时间:2020-12-27

C++中lower_bound函数和upper C++中lower_bound函数和upper

时间:2020-12-27

Copyright © www.juheyunku.com      关于 | 合作 | 声明 | 联系 | 更新 | 地图 | Tags

C++_c++编写简单的计算器程序,首先来看下本人的开发环境

2020-12-25 编辑:fen

首先来看下本人的开发环境

系统: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 = mulaIT之家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; }

代码比较简单,希望大家能够喜欢

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供学习参考!
本文地址为 https://v30.fanwenzhu.com/jiaob/cjj/8830.shtml

相关文章

风云图片

推荐阅读

返回C/C++频道首页