im writing an interactive story game in c++ and for some reason it isn't separating the first and second if, so if i press 1 or 2 both of them get written
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main ()
{
cout << "\nWelcome to Jason's interactive story game.\n";
cout << "Let's begin!\n";
sleep(1);
cout << "There was once a boy named Samuel (a.k.a. Sam). Sam was extremely excited for christmas!";
cout << "Sam couldn't decide whether to wake up at the crack o' dawn and wake his family to open presents ";
cout << "OR wait until 9:00 A.M. and wake up with everyone else. Now it's your turn to choose.\n 1) Wake at the crack o' dawn \n 2) Wake up at 9:00 A.M. with everyone else.";
string beep;
cin >> beep;
{if (beep.compare("1") == 0)
cout << "Sam gets out of bed screaming at the top of his lungs \"GET UP, GET UP EVERYONE IT'S CHRISTMAS!!!\"";
cout << "However Sam forgot that his sister, Sarah hates waking up early, he turns to her bed and she's right there, in front of him with a hammer. *whack!!*";
cout << "******Try again?******\n\n\n\n";
}
{if (beep.compare("2") == 0)
cout << "Sam streches his arms. *Yawnn* He camly turns his head towards the green clock aside his bed. \"Seven o'clock, I better go back to sleep!\"\n";
cout << "*****Two hours later*****\n Sam wakes up and checks the clock again. \"Wow! It's nine-thirty, time to get up!!\" Sam runs around his house and wakes his family up.";
cout << "\"Okay, okay!\" Sam's sister says. Sam pulls everyone in the living room to open presents. Sam stands over his three presents, green red and blue. \n";
cout << "\"Hmm, red, green or blue?!\" Time to help Sam out! Pick: Red, green or blue?";
string present;
cin >> present;
}}
thanks in advance for your help
-jason
Copyright © 2024 Q2A.ES - All rights reserved.
Answers & Comments
Verified answer
You don't want the ==0 in your conditions. Also, you need to use braces properly. (ie: they should follow the ifs)