我试图让我的计算器在完成计算后循环回到顶部?我已经尝试过 while 循环并查看了有关它的教程,但我无法将其置于上下文中。
如果你能告诉我如何在这个程序中实际使用它,那就太好了。
#include<iostream>
using namespace std;
int main() {
double num1, num2;
char op;
cout << "********C++ CALCULATOR********" << endl;
cout << "Please enter your first number" << endl;
cin >> num1;
cout << "Please enter your operand (+, -, *, /)\n" << endl;
cin >> op;
cout << "Please enter your second number\n" << endl;
cin >> num2;
if (op== '+') {
cout << "The answer is: " << num1 + num2 << endl;
} else if (op == '-') {
cout << "The answer is: " << num1 - num2 << endl;
} else if (op == '/') {
cout << "The answer is: " << num1 / num2 << endl;
} else if (op == '*') {
cout << "The answer is: " << num1 * num2 << endl;
} else {
cout << "That was an invalid command!" << endl;
}
}