ligetisplit
New Coder
I am trying to make a bunch of tiny cpp projects to practice the really basic concepts (my first time trying to learn, but I am committed),
is there a way to make this code simpler/easier to read, or perhaps even shorter while improving readability?
Thank you!
[CODE lang="cpp" title="nesting if statement dumb quiz"]//this program will use a nested if statement in the creation of a quiz
#include <iostream>
#include <string>
void Quiz()
{
std::cout << "Welcome to the first quiz, where you can only progress" << '\n' << "through the 5 questions by"
<< " correctly answering all questions correctly in sequence" << "\n\n\n";
std::string question1;
std::cout << "Who said the following: musicians are athletes of the small muscles?" << "\n\n";
std::getline(std::cin, question1);
if (question1 == "Hal Galpin")
{
std::cin.clear();
std::cout << "Correct! Now for the second question..." << '\n';
std::string question2;
std::cout << "What is the capital of the United Arab Emirates?" << "\n\n";
std::getline(std::cin, question2);
if (question2 == "Abu Dhabi")
{
std::cout << "Correct, once again. Please prepare for the third question... " << '\n';
std::string question3;
std::cout << "Who discovered the curvature of spacetime?" << "\n\n";
std::getline(std::cin, question3);
if (question3 == "Albert Einstein")
{
std::cout << "Congratulations... on to question 4, get out your thinking cap" << '\n';
std::string question4;
std::cout << "What is the first letter of the alphabet?" << "\n\n";
std::getline(std::cin, question4);
if (question4 == "a" || "A")
{
std::cout << "Wow, impressive work! Fifth question coming up..." << '\n';
std::string question5;
std::cout << "Who wrote the Declaration of Independence?" << "\n\n";
std::getline(std::cin, question5);
if (question5 == "Thomas Jefferson")
{
std::cout << "Congratulations, you are probably still stupid, but you passed the quiz!";
}else { std::cout << "Wow, you don't know this?"; }
}else { std::cout << "You seriously don't know this??"; }
}else { std::cout << "Come again?"; }
}else { std::cout << "Wow, typical American"; }
}else { std::cout << "Um, you're wrong, LOL"; }
}
int main()
{
Quiz();
return 0;
}[/CODE]
is there a way to make this code simpler/easier to read, or perhaps even shorter while improving readability?
Thank you!
[CODE lang="cpp" title="nesting if statement dumb quiz"]//this program will use a nested if statement in the creation of a quiz
#include <iostream>
#include <string>
void Quiz()
{
std::cout << "Welcome to the first quiz, where you can only progress" << '\n' << "through the 5 questions by"
<< " correctly answering all questions correctly in sequence" << "\n\n\n";
std::string question1;
std::cout << "Who said the following: musicians are athletes of the small muscles?" << "\n\n";
std::getline(std::cin, question1);
if (question1 == "Hal Galpin")
{
std::cin.clear();
std::cout << "Correct! Now for the second question..." << '\n';
std::string question2;
std::cout << "What is the capital of the United Arab Emirates?" << "\n\n";
std::getline(std::cin, question2);
if (question2 == "Abu Dhabi")
{
std::cout << "Correct, once again. Please prepare for the third question... " << '\n';
std::string question3;
std::cout << "Who discovered the curvature of spacetime?" << "\n\n";
std::getline(std::cin, question3);
if (question3 == "Albert Einstein")
{
std::cout << "Congratulations... on to question 4, get out your thinking cap" << '\n';
std::string question4;
std::cout << "What is the first letter of the alphabet?" << "\n\n";
std::getline(std::cin, question4);
if (question4 == "a" || "A")
{
std::cout << "Wow, impressive work! Fifth question coming up..." << '\n';
std::string question5;
std::cout << "Who wrote the Declaration of Independence?" << "\n\n";
std::getline(std::cin, question5);
if (question5 == "Thomas Jefferson")
{
std::cout << "Congratulations, you are probably still stupid, but you passed the quiz!";
}else { std::cout << "Wow, you don't know this?"; }
}else { std::cout << "You seriously don't know this??"; }
}else { std::cout << "Come again?"; }
}else { std::cout << "Wow, typical American"; }
}else { std::cout << "Um, you're wrong, LOL"; }
}
int main()
{
Quiz();
return 0;
}[/CODE]
