简单到令人发指的小程序 ……计算器
看代码,保证你说这程序令人发指程序代码:
// 简单计算器.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include<iostream> #include<math.h> using namespace std; double firstnum,secondnum,thirdnum,resultnum; char sign1,sign2; void input() { cin>>firstnum>>sign1>>secondnum>>sign2>>thirdnum; } void output() { cout<<"="<<resultnum<<'\n'; } double yunsuan() { if(sign1=='+'&&sign2=='+') { resultnum=firstnum+secondnum+thirdnum; } if(sign1=='+'&&sign2=='-') { resultnum=firstnum+secondnum-thirdnum; } if(sign1=='+'&&sign2=='*') { resultnum=firstnum+secondnum*thirdnum; } if(sign1=='+'&&sign2=='/') { resultnum=firstnum+secondnum/thirdnum; } if(sign1=='+'&&sign2=='^')//~~~~~~~~~~第一运算符为加法~~~~~~~~~~~~~~~~~~~~ { resultnum=firstnum+pow(secondnum,thirdnum); } if(sign1=='-'&&sign2=='+') { resultnum=firstnum-secondnum+thirdnum; } if(sign1=='-'&&sign2=='-') { resultnum=firstnum-secondnum-thirdnum; } if(sign1=='-'&&sign2=='*') { resultnum=firstnum-secondnum*thirdnum; } if(sign1=='-'&&sign2=='/') { resultnum=firstnum-secondnum/thirdnum; } if(sign1=='-'&&sign2=='^')//~~~~~~~~~~第一运算符为减~~~~~~~~~~~~~~~~~~~~ { resultnum=firstnum-pow(secondnum,thirdnum); } if(sign1=='*'&&sign2=='+') { resultnum=firstnum*secondnum+thirdnum; } if(sign1=='*'&&sign2=='-') { resultnum=firstnum*secondnum-thirdnum; } if(sign1=='*'&&sign2=='*') { resultnum=firstnum*secondnum*thirdnum; } if(sign1=='*'&&sign2=='/') { resultnum=firstnum*secondnum/thirdnum; } if(sign1=='*'&&sign2=='^')//~~~~~~~~~~~第一运算符为乘~~~~~~~~~~~~~~~~~~~ { resultnum=firstnum*pow(secondnum,thirdnum); } if(sign1=='/'&&sign2=='+') { resultnum=firstnum/secondnum+thirdnum; } if(sign1=='/'&&sign2=='-') { resultnum=firstnum/secondnum-thirdnum; } if(sign1=='/'&&sign2=='*') { resultnum=firstnum/secondnum*thirdnum; } if(sign1=='/'&&sign2=='/') { resultnum=firstnum/secondnum/thirdnum; } if(sign1=='/'&&sign2=='^')//~~~~~~~~~~~第一运算符为除~~~~~~~~~~~~~~~~~~~ { resultnum=firstnum/pow(secondnum,thirdnum); } if(sign1=='^'&&sign2=='+') { resultnum=pow(firstnum,secondnum)+thirdnum; } if(sign1=='^'&&sign2=='-') { resultnum=pow(firstnum,secondnum)-thirdnum; } if(sign1=='^'&&sign2=='*') { resultnum=pow(firstnum,secondnum)*thirdnum; } if(sign1=='^'&&sign2=='/') { resultnum=pow(firstnum,secondnum)/thirdnum; } if(sign1=='^'&&sign2=='^')//~~~~~~~~~~第一运算符为幂运算~~~~~~~~~~~~~~~~~~~~ { resultnum=pow(firstnum,secondnum); resultnum=pow(resultnum,thirdnum); } return 0; } int _tmain(int argc, _TCHAR* argv[]) { for(;;) { cout<<"现在开始运算:"<<'\n'; input(); yunsuan(); output(); } return 0; }。。。