Program Has Stuff Wrong Wit It

This is a discussion on Program Has Stuff Wrong Wit It within the C++ Programming forums, part of the General Programming Boards category; Hi. I am working on my first ever text adventure program. It has no errors, but like it says stuff ...

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    97

    Program Has Stuff Wrong Wit It

    Hi. I am working on my first ever text adventure program. It has no errors, but like it says stuff wrong. If i put in left, it thinks I went right. run the damn program and see what i mean! btw, i am only 1/3 done wit it.-

    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
    char way1;
    char way2;
    char way3;
    char way4;
    
    cout << "Welcome to Ryan's First Text Adventure Game!";
    cout << "\nLets start shall we?!";
    cout << "\nOne day, you and your friend were bored and decided to go have some ";
    cout << "\nfun. There was a house that people said was haunted on the biggest ";
    cout << "\nhill in your town. So you guys went up there and knocked. The door ";
    cout << "\ncreaked open but no one was there! So you walked in and the door ";
    cout << "\nslammed behind you and locked! So here is where it all starts, the ";
    cout << "\nescape from the House From Hell....";
    cout << "\nWell, you guys decide to start looking around. Should you start left, ";
    cout << "\nright, or straight?(l/r/s): ";
    cin >> way1;
        if(way1 == 'l')
            cout << "\nYou guys walk through the door to the left and see 2 more doors.";
            cout << "\nDo you want to guys want to go left again or straight ahead?(l/s)";
            cin >> way2;
                    if(way2 == 'l')
                          cout << "\nYou guys go left and a demon appears. Do you want ";
                          cout << "\nto fight it or run?(f/r): ";
                          cin >> way4;
                    if(way2 == 's')
                          cout << "\nYou guys go straight into a Great Hall. There is 1 door ";
                          cout << "\non each side. Do you guys go left or right?(l/r): ";
                          cin >> way3;
                        if (way3 == 'l')
                            cout << "\nYou go left and there is corpses and bones and skulls everywhere!";
                            cout << "\nThey come alive and kill you guys! O well, Thanks For Playing!" << endl;
                                if(way4 == 'f')
                                     cout << "\nYou guys start to fight it but it breathes fire everywhere and you all burn and die. ";
                                     cout << "\nThanks for playing!" <<endl;
                                if(way4 == 'r')
                                     cout << "\nYou all start to run away but so fast you can't see and fall down a pit. ";
                                     cout << "\nYou guys stay and rot there. Ughh!! Thanks for playing!" << endl;                
                                
    system("pause");
    return 0;
    }

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    You left out all of the braces for your if statements. The way it is now, it will only execute the first statement after the if.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    You also didn't use a specific thread title. Most of the people starting a thread in this forum have a "Program with stuff wrong with it"
    Away.

  4. #4
    Registered User
    Join Date
    Jul 2003
    Posts
    97
    Ok, I fixed the if statements with the brackets. But it still is wrong. Like if I say go left, then straight, it thinks I went left, then left again. Run it and look!

    Revised with brackets for the if statements-
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
    char way1;
    char way2;
    char way3;
    char way4;
    
    cout << "Welcome to Ryan's First Text Adventure Game!";
    cout << "\nLets start shall we?!";
    cout << "\nOne day, you and your friend were bored and decided to go have some ";
    cout << "\nfun. There was a house that people said was haunted on the biggest ";
    cout << "\nhill in your town. So you guys went up there and knocked. The door ";
    cout << "\ncreaked open but no one was there! So you walked in and the door ";
    cout << "\nslammed behind you and locked! So here is where it all starts, the ";
    cout << "\nescape from the House From Hell....";
    cout << "\nWell, you guys decide to start looking around. Should you start left, ";
    cout << "\nright, or straight?(l/r/s): ";
    cin >> way1;
        if(way1 == 'l');
            {
            cout << "\nYou guys walk through the door to the left and see 2 more doors.";
            cout << "\nDo you want to guys want to go left again or straight ahead?(l/s)";
            cin >> way2;
            }
                    if(way2 == 'l');
                          {
                          cout << "\nYou guys go left and a demon appears. Do you want ";
                          cout << "\nto fight it or run?(f/r): ";
                          cin >> way4;
                          }
                    if(way2 == 's');
                          {
                          cout << "\nYou guys go straight into a Great Hall. There is 1 door ";
                          cout << "\non each side. Do you guys go left or right?(l/r): ";
                          cin >> way3;
                          }
                        if (way3 == 'l');
                            {
                            cout << "\nYou go left and there is corpses and bones and skulls everywhere!";
                            cout << "\nThey come alive and kill you guys! O well, Thanks For Playing!" << endl;
                            }
                                if(way4 == 'f');
                                     {
                                     cout << "\nYou guys start to fight it but it breathes fire everywhere and you all burn and die. ";
                                     cout << "\nThanks for playing!" <<endl;
                                     }
                                if(way4 == 'r');
                                     {
                                     cout << "\nYou all start to run away but so fast you can't see and fall down a pit. ";
                                     cout << "\nYou guys stay and rot there. Ughh!! Thanks for playing!" << endl;
                                     }                
                                
    system("pause");
    return 0;
    }

  5. #5
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    You don't put a ; after an if:

    Code:
    if (x == 3); // this if does nothing
    {
    /*...This always is executed...*/
    }
    
    if (x == 3) // this is the correct way
    {
    /*...This is executed only if x is 3...*/
    }

  6. #6
    Registered User
    Join Date
    Jul 2003
    Posts
    97
    Ok thank you! I got confused.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What is wrong with my code? My first program......
    By coreyt1111 in forum C++ Programming
    Replies: 11
    Last Post: 11-14-2006, 01:03 PM
  2. Whats wrong with this program - Output of a series
    By duffmckagan in forum C Programming
    Replies: 2
    Last Post: 07-26-2006, 09:57 AM
  3. Whats wrong with my program?
    By Ruflano in forum C++ Programming
    Replies: 4
    Last Post: 02-13-2002, 02:54 PM
  4. command line program, something wrong in the argv
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 09-26-2001, 09:36 AM
  5. what's wrong with my newbie program??
    By insoolated in forum C++ Programming
    Replies: 1
    Last Post: 09-14-2001, 08:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21