我是这里的新手程序员,所以请善待:
我正在编写一个执行简单算术的 C++ 程序。我的一切在语法上都是正确的,但是出现了多个答案,例如,当使用 + 时,计算机显示答案之后的每个单独的 cout 语句,但是使用其他运算符的后续 cout 语句(-,*,/)显示只有其中几个。我可以在这里使用帮助是代码。
//This program will take two integers and compute them in basic arithmetic
//in the way that a simple calculator would.
#include <iostream>
using namespace std;
int main ()
{
int num1;
int num2;
double sum, difference, product, quotient;
char operSymbol;
cout << "Please enter the first number you would like to equate: ";
cin >> num1;
cout << "Please enter the second number: ";
cin >> num2;
cout << "Please choose the operator you would like to use (+, -, *, /): ";
cin >> operSymbol;
switch (operSymbol)
{
case '+':
sum = num1 + num2;
cout << "The sum is: " << sum << endl;
case '-':
difference = num1 - num2;
cout << "The difference is: " << difference << endl;
case '*':
product = num1 * num2;
cout << "The product is: " << product << endl;
case '/':
quotient = num1 / num2;
cout << "The quotient is: " << quotient << endl;
}
system("Pause");
return 0;
}