以前写的源码,简单的计算器,新手入门实现。
//一次计算器
#include <iostream>
using namespace std;
//“+”运算
float add(float front,float after){
return front+after;
}
//“-”运算
float reduce(float front,float after){
return front-after;
}
//“*”运算
float ride(float front,float after){
return front*after;
}
//“/”运算
float get_rid_of(float front,float after){
return front/after;
}
//主函数
int main(){
float front,after;
char symbol;
cout<<"一次计算器"<<endl<<"欢迎你使用!"<<endl<<endl;
cout<<"请输入第一个数:";
cin>>front;
cout<<"请输入运算符号:";
cin>>symbol;
cout<<"请输入第二个数:";
cin>>after;
switch(symbol)
{
case '+':cout<<"结果为:"<<add(front,after)<<endl;break;
case '-':cout<<"结果为:"<<reduce(front,after)<<endl;break;
case '*':cout<<"结果为:"<<ride(front,after)<<endl;break;
case '/':cout<<"结果为:"<<get_rid_of(front,after)<<endl;break;
default:cout<<"Error!无法识别的符号!!!!!!!!!!!!!!!!!!!!!"<<endl;
}
cout<<"-------------程序运行结束,欢迎下次再来!The program has finished running. Welcome to come again next time!-------------";
return 0;
}