I'm learning C++ and I'm working on a project that ask a question and leads you to another question. Like a text adventure. I'm have an issue in particular part where when you answer the question in an if or else if statement the else statement also runs.
What I'm trying to do is have the person answer the question then go to the next question. If the person answer other then the multiple choice question they get an error. I'm just wondering what I'm doing wrong and how can I fix it.
#include <iostream>
int main ()
{
char ch1;
char q2;
char q3;
//// Question 1
std::cout << "Welcome to My Program. \n";
std::cout << "Everyday we wake up in a particular mood that leads our day for the most part. \n";
std::cout << "Which mood are you waking up to? \n \n";
std::cout << "A.) Angry \n";
std::cout << "B.) Blah \n";
std::cout << "C.) Happy \n";
std::cin >> ch1;
if (ch1 == 'a' || ch1 == 'A') /// question 2
{
std::cout << "We are off to a bad start, Everyone sucks. \n\n";
std::cout << "What are you going to do next to change your day? \n";
std::cout << "A.) GO GET COFFEE!! \n";
std::cout << "B.) Just Go to Work \n";
std::cout << "C.) Go Back To Sleep \n";
std::cin >> q2;
}
else if (ch1 == 'b' || ch1 == 'B') /// question 3
{
std::cout << "Nothing seems to motivate you and all you want to do is lay in bed. \n";
std::cout << "What are you going to do next to change your day? \n";
std::cout << "A.) GO GET COFFEE!! \n";
std::cout << "B.) Ditch work to go to the beach! \n";
std::cout << "C.) Go Back To Sleep \n";
std::cin >> q3;
}
else if ( ch1 == 'c' || ch1 == 'C')
{
std::cout << "Nothing Can Ruin Your Day!! \n";
std::cout << "ENJOY!!";
}
else
{
std::cout <<"Error, Not A Choice";
}
/// Question 2
if (q2 == 'a' || q2 == 'A')
{
std::cout << "Things Look Better, You might survive";
}
else if (q2 == 'b' || q2 == 'B')
{
std::cout << "You're a Ticking Time Bomb!";
}
else if ( q2 == 'c' || q2 == 'C')
{
std::cout << "Nothing can beat sleep!!" ;
}
else
{
std::cout <<"Error, Not A Choice" ;
}
///Question 3
if (q3 == 'a' || q3 == 'A')
{
std::cout << "Things Look Better, You might survive";
}
else if (q3 == 'b' || q3 == 'B')
{
std::cout << "You're day Just got Better! Enjoy!" ;
}
else if ( q3 == 'c' || q3 == 'C')
{
std::cout << "Nothing can beat sleep!!" << std::endl;
}
else
{
std::cout <<"Error, Not A Choice";
}
}
Aucun commentaire:
Enregistrer un commentaire