c++写的简单计算器
2016-05-03 22:37
435 查看
今天偶然看到有人用计算器于是就用c++写了一个简单的计算器
由于临时写的,只能算int类型的简单加,减,乘,除。代码如下://四则运算(由于csdn有bug不能用<<所以用//代替)
头文件:
{
“stdafx.h”
iostream
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;
}
//技术交流1099723261@qq.com
欢迎来我博客和邮箱留言!
技术交流!!!!
相关文章推荐
- 嵌入式开发为什么要学C语言
- C语言的内存对齐机制
- Cpp_src.vim
- C++基础实例-文件Io等(5)
- C/C++头文件一览
- 设计模式C++学习笔记之十一(c/c++面试笔试题)
- C++11中的POD
- PCL库文件配置那点事
- c语言简易计算器
- 设计模式(C++) -----单例模式
- Problem J: C语言实验——for循环打印图形(循环结构)
- leetcode 345 Reverse Vowels of a String C++
- C++常用头文件
- C++简单线程开启
- Problem G: C语言实验--算算男生女生的比例
- 【VS开发】VC++ 获取系统时间、程序运行时间(精确到秒,毫秒)的五种方法
- C++第4次上机实验
- c++第五次实验
- C++函数的重载/覆盖/隐藏
- 直接插入排序的c语言实现