C ++ Harry Potter Sorting Quiz

Code is here: https://gist.github.com/ad4d69ce82b8fb8a0695759ca899c18b

I am getting an exclamation mark when I should get an answer.

$ g++ sortinghat.cpp

$ ./a.out

=====================

The Sorting Hat Quiz!

=====================

Q1) When I’m dead, I want people to remember me as:

  1. The Good
  2. The Great
  3. The Wise
  4. The Bold

1

Q2) Dawn or Dusk?:

  1. Dawn
  2. Dusk

1

Q3) Which kind of instrument most pleases your ear?:

  1. The violin
  2. The trumpet
  3. The Piano
  4. The drum

2

Q4) Which road tempts you most:

  1. The wide, sunny grassy lane
  2. The narrow, dark, lantern-lit alley
  3. The twisting, leaf-strewn path through woods
  4. The cobbled street lined (ancient buildings)

3

!

$

Can anyone tell me what I am missing?

I got Hufflepuff! when I ran this code (with random answers).

Try to isolate what answers make it only output the exclamation point. There’s probably a small error around that code.

1 Like

I only get your output when I intentionally give invalid answers causing all four scores to end up with values of 0. That seems to be expected behavior. Using the answers in your example, I get, “Gryffindor!”
There doesn’t appear to be anything wrong that I can see. Are you sure the code you ran is the same as the code in your gist?

2 Likes