为什么不显示最终产品?

Why does it not display the final product?

我想编写一个程序,让用户进行测验,然后他们被分配到哈利波特的其中一间房子,但最后房子的输出没有显示。我在这个项目中使用 C++,我还使用 Visual Studio 代码作为我的 IDE。我希望能够放置备选方案,当用户输入它们时,它会取一个平均值并最终为他们分配一个房子。 在此处显示的代码上,我使用 ... 来显示重复并大大缩短了代码。所以在答案变量中,有 10 个变量,从 1 到 10,每个变量的值为 0。关于问题,有十个,但我只显示了第一个和最后一个。有4个选项,分别是1、2、3、4。有一个if语句代表对应的答案(question1,answer1;question2,answer2等等)。另外,如果代码有点不清楚,我很抱歉,因为我必须展示大部分代码,但如果代码多于描述,它不会让我post。房子现在不显示怎么解决?任何提示将不胜感激,谢谢!

这是代码:

#include <iostream>
using namespace std;
int main() {
int gryffindor = 0;
...
int slytherin = 0;

int answer1 = 0;
...
int answer10 = 0;

cout << "Let's test which house you belong to. Test beginning in: \n 3 \n 2 \n 1 \n 0 \n Good luck \n";
cout << "What colour do you like most? \n 1. Red ... \n 4. Yellow \n";
cin >> answer1;
if (answer1 == 1) {
gryffindor++;
} else if (answer1 == 2) {
hufflepuff++;
} else if (answer1 == 3) {
ravenclaw++;
} else if (answer1 == 4) {
slytherin++;
} else {
cout << "Try again, answer invalid: ";
cin >> answer1;
}
...
cout << "If the sorting hat put you in what you think is the wrong house you would \n 1. Softly make a comment \n ... 4. Go happily to the house you were assigned to \n";
cin >> answer10;
if (answer10 == 1) {
gryffindor++;
}
...
else {
cout << "Try again, answer invalid: ";
cin >> answer10;
}

// Finding the houses
int MaxPoints;
string YourHouse;

if (gryffindor > MaxPoints) {
MaxPoints = gryffindor;
YourHouse = "Gryffindor";
}

if (hufflepuff > MaxPoints) {
MaxPoints = hufflepuff;
YourHouse = "Hufflepuff";
}

if (ravenclaw > MaxPoints) {
MaxPoints = ravenclaw;
YourHouse = "Ravenclaw";
}

if (slytherin > MaxPoints) {
MaxPoints = slytherin;
YourHouse = "Slytherin";
}

cout << "The Hat has decided...Your house is: " << YourHouse << "! \n";

system("pause");
return 0;
}

当您写“但最后房子的输出没有显示”时,您的意思是其他文本确实显示,但具体不是房子名称?还是文字的none显示

在前一种情况下,您可能想给变量 MaxPoints 一个初始值,因为目前它的值是未定义的:

int MaxPoints = -1;