手搓一个计算器
2024-11-21 19:57:35
发布于:北京
直接手搓一个计算器!
#include <bits/stdc++.h>
using namespace std;
double a,b;
char c;
int main(){
cout << "Calculator Console Application" << endl << endl;
cout << "Please enter the operation to perform. Format: a+b | a-b | a*b | a/b" << endl;
cin >> a >> c >> b;
if(c == '/' && b == 0){
cout << "Attempted to divide by zero!" << endl;
}
else if(c == '+'){
cout << a + b << endl;
}
else if(c == '-'){
cout << a - b << endl;
}
else if(c == '*'){
cout << a * b << endl;
}
else if(c == '/'){
cout << a / b << endl;
}
return 0;
}
全部评论 1
顶
5小时前 来自 北京
0
有帮助,赞一个