c 计算器源代码

来源:互联网 时间:2025-01-02 06:03:01 人看过

这个代码可以实现计算器功能

#include"stdafx.h"

#include<iostream>

#include<stdio.h>

usingnamespacestd;

voidadd()

{

printf("输入要计算的加数(例如ab)\n");

intadda=0,addb=0,addc=0;

cin>>adda;

cin>>addb;

addc=adda+addb;

cout<<adda<<"加"<<addb<<"等于"<<addc<<endl;

}

voidsubstraction()

{

printf("输入要计算的减数(例如ab)\n");

intsuba=0,subb=0,subc=0;

cin>>suba;

cin>>subb;

subc=suba-subb;

cout<<suba<<"减"<<subb<<"等于"<<subc<<endl;

}

voidmultiplication()

{

printf("输入要计算的乘数(例如ab)\n");

intmula=0,mulb=0,mulc=0;

cin>>mula;

cin>>mulb;

mulc=mula*mulb;

cout<<mula<<"乘"<<mulb<<"等于"<<mulc<<endl;

}

voidpision()

{

printf("输入要计算的除数(例如ab)\n");

intdsa=0,dsb=0,dsc=0,dsd=0;

cin>>dsa;

cin>>dsb;

dsc=dsa/dsb;

dsd=dsa%dsb;

cout<<dsa<<"除"<<dsb<<"等于"<<dsc<<"余"<<dsd<<endl;

}

voidoperation()//运算函数

{

printf("输入数据选择做那种运算\n");

printf("输入0选择退出,1做加法,2做减法,3做乘法,4做除法(保留余数)\n");

intoperatione=0;

cin>>operatione;

cout<<endl;

try

{

if(operatione==1)

{

//加法

add();

}

elseif(operatione==2)

{

//减法

substraction();

}

elseif(operatione==3)

{

//乘法

multiplication();

}

elseif(operatione==4)

{

//出发

pision();

}

elseif(operatione==0)

{

exit(0);

}

else

{

throw1;

}

}

catch(inti)

{

cout<<"输入错误"<<endl;

}

operation();

}

intmain()

{

printf("欢迎使用本计算器");

operation();

return0;

}。

免责声明:本站内容仅用于学习参考,信息和图片素材来源于互联网,如内容侵权与违规,请联系我们进行删除,我们将在三个工作日内处理。联系邮箱:chuangshanghai#qq.com(把#换成@)

本文标签

c语言计算器程序代码

免责声明:本站内容仅用于学习参考,信息和图片素材来源于互联网,如内容侵权与违规,请联系我们进行删除,我们将在三个工作日内处理。

联系邮箱:chuangshanghai#qq.com(把#换成@)

Copyright © 转乾企业管理-百问网 版权所有

黔ICP备2023009682号