Help with my Sorting Hat

#include

int main () {

int gryffindor = 0, hufflepuff = 0, ravenclaw = 0, slytherin = 0;
int answer1 = 0, answer2 = 0, answer3 = 0, answer4 = 0;

std::cout << “==================================\n”;
std::cout << “Welcome to Hogwarts Muggles. “;
std::cout << “\n”;
std::cout << “It’s time for the Sorting Hat Quiz!\n”;
std::cout << “==================================\n”;
std::cout <<“Q1) When I’m dead, I want people to remember me as: \n”;
std::cout <<”\n”;
std::cout <<“The Good\n”;
std::cout <<“The Great\n”;
std::cout <<“The Wise\n”;
std::cout <<“The Bold\n”;

std::cin >> answer1;

if (answer1 == 1) {

hufflepuff++;
}
else if (answer1 == 2) {
slytherin++;
}
else if (answer1 == 3) {
ravenclaw++;
}
else if (answer1 == 4) {
gryffindor++;
}
else {
std::cout << “Invalid input\n”;
}
std::cout <<“Q2) Dawn or Dusk?\n”;
std::cout <<“1) Dawn\n”;
std::cout <<“2) Dusk\n”;

std::cin >> answer2;

if (answer2 == 1) {
gryffindor++;
ravenclaw++;
}
else if (answer2 == 2){
hufflepuff++;
slytherin++;
}
else {
std::cout << “Invalid Input.\n”; }

std::cout << “Q3) Which kind of instrument most pleases your ear?\n”;
std::cout << “\n”;

std::cout << “1. The violin\n”;
std::cout << “2. The trumpet\n”;
std::cout << “3. The piano\n”;
std::cout << “4. The drum\n”;

if (answer3 == 1) {
slytherin++;
}
else if (answer3 == 2) {
hufflepuff++;
}
else if (answer3 == 3) {
ravenclaw++;
}
else if (answer3 == 4) {
gryffindor++;
}
else{
std::cout << “Invalid input\n”;
}
std::cout << “Q4) Which road tempts you most?\n”;
std::cout << “\n”;

std::cout << “1. The wide, sunny grassy lane\n”;
std::cout << “2. The narrow, dark, lantern-lit alley\n”;
std::cout << “3. The twisiting, leaf-strewn path through woods\n”;
std::cout << “4. The cobbled street lined (ancient buildings)\n”;
std::cout << “\n”;

if (answer4 == 1) {
hufflepuff++;
}
else if(answer4 == 2) {
slytherin++;
}
else if(answer4 == 3) {
gryffindor++;
}
else if(answer4 == 4) {
ravenclaw++;
}
else{
std::cout << “Invalid Input\n”;
}

std::cout >> “Congratulations on being sorted into…\n”;
int (max = 0)
std::string house;
if (gryffindor > max) {
max = gryffindor;
house = “Gryffindor”;
}
if (hufflepuff > max) {
max = hufflepuff;
house = “Hufflepuff”;
}
if (ravenclaw > max) {
max = ravenclaw;
house = “Ravenclaw”;
}
if (slytherin > max) {
max = slytherin;
house = “Slytherin”;
}

std::cout << house << “!\n”;

}

I keep receiving an error code that max has not been defined but for some reason when I try to initialize it as a variable it won’t output correctly.

Why do you have the parenthesis ( and ) there?

Maybe changing that to
int max = 0;
would help.

3 Likes

I removed the parenthesis, yet still I get the same error code so I don’t believe that was the issue.

edit: After closing the complier and running it again without the parentheses it seems to run smoothly now. Thanks for the tip!