【发布时间】:2021-01-14 08:30:44
【问题描述】:
如何让用户输入两个数字,然后显示这些选项:
和, 平均的, 最大, 最低限度, 出口。然后由于用户选择,程序显示答案,这个过程一直持续到用户输入数字5。
我的代码不能正常工作。代码如下:
#include <stdio.h>
#include <iostream>
using namespace std;
int main() {
int x, y, choice;
char sum, average, max, min;
cout << "Enter two numbers: " << endl;
cin >> x >> y;
cout << "Choose one of these options: \n";
cout << " sum - average - max - min - exit " << endl;
choice == sum || average || max || min;
cin >> choice;
sum == x + y;
max == x > y || y > x;
if (choice == sum) {
cout << "The sum is: " << x + y << endl;
}
if (choice == average) {
cout << "The average is: " << x / y << endl;
}
if (choice == max&& x > y) {
cout << "The maximum is: " << x << endl;
} else
cout << " The maximum is: " << y << endl;
if (choice == min&& x < y) {
cout << "The minimun is: " << x << endl;
} else
cout << " The minimun is: " << y << endl;
while (true) {
string choice;
cin >> choice;
if (choice == "5") {
break;
}
}
return 0;
}
【问题讨论】:
-
我认为您将变量名与字符串值混淆了。您可能需要good book。
标签: c++