Harry Potter Sorting Quiz
"Coding is today's language of creativity" - Marie Clawe
Harry Potter Sorting Quiz
I created a fun quiz using C++ that quizzes the user and places them in one of the four Harry Potter houses. I learned how to use the switch function while coding this!
Instructions
Copy the code from the end of this page
Paste it into the compiler.
Hit the Run button
Play!
Demo
Code
#include <iostream>
using namespace std;
int main() {
int gryffindor = 0, hufflepuff = 0, ravenclaw = 0, slytherin = 0;
int answer1, answer2, answer3, answer4;
cout << "\n✨ 🧙 THE SORTING HAT QUIZ! 🧙 ✨\n\n";
cout << "Q1) I want people to remember me as...\n 1) The Kind\n 2) The Good\n 3) The Wise\n 4) The Brave\nAnswer: ";
cin >> answer1;
cout << "\n";
switch(answer1){
case 1:
hufflepuff++;
break;
case 2:
slytherin++;
break;
case 3:
ravenclaw++;
break;
case 4:
gryffindor++;
break;
default:
cout << "Invalid Input\n";
break;
}
cout << "Q2) When I die, I most hope to...\n 1) Be wealthy enough to provide for many generations of your family\n 2) Have acheived success and traveled the world\n 3) Be surrounded by lifelong friends\n 4) Have learned everything there is to know\nAnswer: ";
cin >> answer2;
cout << "\n";
switch(answer2){
case 1:
slytherin++;
break;
case 2:
gryffindor++;
break;
case 3:
hufflepuff++;
break;
case 4:
ravenclaw++;
break;
default:
cout << "Invalid Input\n";
break;
}
cout << "Q3) Which road temps your most?\n 1) The wide, sunny, grassy lane\n 2) The narrow, dark, lantern-lit alley\n 3) The twisting, leaf-strewn path through the woods\n 4) The cobbled street lined with ancient buildings\nAnswer: ";
cin >> answer3;
cout << "\n";
switch(answer3){
case 1:
hufflepuff++;
break;
case 2:
slytherin++;
break;
case 3:
gryffindor++;
break;
case 4:
ravenclaw++;
break;
default:
cout << "Invalid Input\n";
break;
}
cout << "Q4) What house do YOU wish to be in?\n 1) Gryffindor\n 2) Slytherin\n 3) Hufflepuff\n 4) Ravenclaw\nAnswer: ";
cin >> answer2;
cout << "\n";
switch(answer2){
case 1:
gryffindor++;
break;
case 2:
slytherin++;
break;
case 3:
hufflepuff++;
break;
case 4:
ravenclaw++;
break;
default:
cout << "^Invalid Input\n";
break;
}
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\n";
std::cout << gryffindor*25 << "% Gryffindor 🦁\n"
<< slytherin*25 << "% Slytherin 🐍\n"
<< hufflepuff*25 << "% Hufflepuff 🦡\n"
<< ravenclaw*25 << "% Ravenclaw 🐦⬛\n";
}