text based video game....please don't question it.

please help. at line 26, the program ends. the not equal to "eric" portion of the code is not working as it should. Any advice? Thanks.


#include <iostream>

using namespace std;

int choice;
string name;
string tf;
int age;
int main(){


cout << "You are standing outside a wrecked house. What do you do? \n 1.Go inside \n 2. Look through window \n 3. Walk around/examine house " <<endl;
cin>>choice;
if (choice==1){
cout <<"A strange group of people attack you and rape you. the end." <<endl;
}
if (choice==2){
cout <<"A giant sword stabs you through the eye. You live but you cannot remove the \n sword and carry it in your eye forever and die by infection...mwahaha" <<endl;
}

if (choice==3){
cout <<"A strange man confronts you. 'what is your name kid,' he asks. You reply: " <<endl;
cin >>name;
if (name=="eric"){
cout <<"You have just been ass-raped. You never walk again. The end." <<endl;
if (name!="eric"){
cout <<"He replies: 'what a great name, wanna be friends?'. Yes or no?" <<endl;
cin >>tf;
if (tf=="true"){
cout <<"Your new friend loves frolicking through minefields. You both blow up and meet an untimely death" <<endl;

}
if (tf=="false"){
cout <<"'Good, I have plenty of friends,' he replies. You wander dejectedly, moping. A girl on the street offers you sex. You accecpt. A cop finds you two and asks your age. How old are you?" <<endl;

}
}
}
}

}
This is what you have (except I formatted it a little differently)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
if (choice==3)
{
    cout <<"A strange man confronts you. 'what is your name kid,' he asks. You reply: " <<endl;
    cin >>name;
    if (name=="eric")
    {
        cout <<"You have just been ass-raped. You never walk again. The end." <<endl;
        if (name!="eric")
        {
            cout <<"He replies: 'what a great name, wanna be friends?'. Yes or no?" <<endl;
            cin >>tf;
            if (tf=="true")
            {
                cout <<"Your new friend loves frolicking through minefields. You both blow up and meet an untimely death" <<endl;
            }
            // ... 

See your problem?
haha no i don't really see my problem.
Great example of how formatting is absolutely crucial. ESPECIALLY when learning.

Too often have I seen people say "I don't really care about formatting for now, I just want it to work". It's not just to make your code pretty and readable, but it's also to help detect any problems early. It helps YOU to understand the code.
you mean if alignment of the lines?
1
2
3
 cout <<"He replies: 'what a great name, wanna be friends?'. Yes or no?" <<endl;
            cin >>tf;
            if (tf=="true")

see an error now?
also remember to watch your brackets.
also another formatting program error.
1
2
3
4
5
int choice;
string name;
string tf;
int age;
int main(){

declaring variables as global is not a good thing to do unless you know exactly why and how to use this scope of use. it is better practice to declare them where they are used to avoid errors when you get into functions and so on.
1
2
3
4
5
int main(){
int choice;
string name;
string tf;
int age;
doing this declares the variables only in the main function.
Last edited on
You want to do it this way: I've explained the differences in comments

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
if (choice==3)
{
    cout <<"A strange man confronts you. 'what is your name kid,' he asks. You reply: " <<endl;
    cin >>name;
    if (name=="eric")
    {
        cout <<"You have just been ass-raped. You never walk again. The end." <<endl;
    } // You missed a closing bracket here
    if (name!="eric")  // You could replace this with a simple "else"
    {
        cout <<"He replies: 'what a great name, wanna be friends?'. Yes or no?" <<endl;
        cin >>tf;
        if (tf=="Yes") // unless they typed "true" this is probably what you want.
        {
            cout <<"Your new friend loves frolicking through minefields. You both blow up and meet an untimely death" <<endl;
        }
            // ...  
Last edited on
Topic archived. No new replies allowed.