C++ Sorting hat won't show questions when compile

:grinning:Hello there! I’m currently working on the c++ sorting hat quiz project, after following the steps and compile. It only showed the first question then I press enter, the rest of the questions are not showing up in the terminal. Is there something I’m missing? Thank you so much for your time and help!

#include <iostream>

int main() {

  int gryffindor = 0;
  int hufflepuff = 0;
  int ravenclaw = 0;
  int slytherin = 0;

  int answer1, answer2, answer3, answer4;

  std::cout << "========================\n";
  std::cout << "The Sorting Hat Quiz!\n";
  std::cout << "========================\n\n";

  //question1:
  std::cout << "Q1) When I'm dead, I want people to remember me as:\n\n";
  std::cout << "  1) The Good\n";
  std::cout << "  2) The Great\n";
  std::cout << "  3) The Wise\n";
  std::cout << "  4) 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";
  }

  //question 2:
  std::cout << "Q2) Dawn or Dusk?\n\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";
  }

  //question 3:
  std::cout << "Q3) Which kind of instrument most pleases your ear?\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";

  std::cin >> answer3;

  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";
  }

  //question 4:
  std::cout << "Q4) Which road tempts you most?\n";
  std::cout << " 1) The wide, sunny grassy lane\n";
  std::cout << " 2) The narrow, dark, lantern-lit alley\n";
  std::cout << " 3) The twisting, leaf-strewn path through woods\n";
  std::Cout << " 4) The cobbled street lined (ancient buildings)\n";

  std::cin >> answer4;

  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";
  }

  //final score
  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";

  return = 0;
}

I copied and pasted it into repl.it and got these compiler errors. If you fix those up, it may work after that.

 clang++-7 -pthread -std=c++17 -o main main.cpp
main.cpp:39:8: error: no member named 'Cout' in namespace 'std'; did you mean
      'cout'?
  std::Cout << " 1) Dawn\n";
  ~~~~~^~~~
       cout
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/iostream:61:18: note: 
      'cout' declared here
  extern ostream cout;          /// Linked to standard output
                 ^
main.cpp:80:8: error: no member named 'Cout' in namespace 'std'; did you mean
      'cout'?
  std::Cout << " 4) The cobbled street lined (ancient buildings)\n";
  ~~~~~^~~~
       cout
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/iostream:61:18: note: 
      'cout' declared here
  extern ostream cout;          /// Linked to standard output
                 ^
main.cpp:99:20: error: use of undeclared identifier 'max'
  if (gryffindor > max) {
                   ^
main.cpp:100:5: error: use of undeclared identifier 'max'
    max = gryffindor;
    ^
main.cpp:102:21: error: use of undeclared identifier 'max'
  }if (hufflepuff > max) {
                    ^
main.cpp:103:5: error: use of undeclared identifier 'max'
    max = hufflepuff;
    ^
main.cpp:105:20: error: use of undeclared identifier 'max'
  }if (ravenclaw > max) {
                   ^
main.cpp:106:5: error: use of undeclared identifier 'max'
    max = ravenclaw;
    ^
main.cpp:108:20: error: use of undeclared identifier 'max'
  }if (slytherin > max) {
                   ^
main.cpp:109:5: error: use of undeclared identifier 'max'
    max = slytherin;
    ^
main.cpp:114:10: error: expected expression
  return = 0;
         ^
11 errors generated.
compiler exit status 1
 ^C
 
2 Likes

Thank you davejandrea !! I’ve worked out the issues and it compiled. Thank you for your help and your time! :heart:

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.