I feel stupid having to ask but.......

This is a discussion on I feel stupid having to ask but....... within the C++ Programming forums, part of the General Programming Boards category; ok i have just started making a text-adventure and i already ran into a problem. I it so simple it ...

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    17

    I feel stupid having to ask but.......

    ok i have just started making a text-adventure and i already ran into a problem. I it so simple it is sad but i can figuer it out.
    here is the code:
    Code:
    #include <iostream>
    #include <stdlib.h>
    
    int main(int argc, char *argv[])
    {
    
    cout<<"\t\t\t\tTHE";
    cout<<"\t\t\t\t\t\t\t\t";
    cout<<"\t\t  TEMPLE";
    cout<<"\t\t\t\t\t\t\t\t";
    cout<<"\t   OF";
    cout<<"\t\t\t\t\t\t\t\t";
    cout<<"\t\t    TYR";
    cout<<"\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t1 : Play";
    cout<<"\t\t\t\t\t\t\t\t\t2 : Exit";
    
    int playorexit;
    
    cin>> playorexit;
    if(playorexit==1);
            {
            cout<<" Thanks for deciding to play!";
            }
    if(playorexit==2);
            {
            system("PAUSE");
            return 0;
            }
                                                                                                               system("PAUSE");	
      return 0;
    }
    what happens is when the user selects 1 it says thanks for deciding to play, but when the user selects 2 it displays thanks for deciding to play as well as exiting. Can anybody suggest a solusion?

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    You don't want the semi-colons at the end of the lines with if().

    You might also want to look up things like endl and flush. A damn site easier than all those tabs.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Check out the <iomanip> header as well.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  4. #4
    Registered User
    Join Date
    Aug 2003
    Posts
    17
    Thanks guys, i know it was kinda a dumb question but i had to ask.

  5. #5
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    That code won't compile. You have this '#include <iostream>' which implies the newer headers which are inclosed in the namespace std. Yet you don't have a using statement, and you don't use std:: for your cout statements.

    Place 'using namespace std;' (w/o the quotes) under the includes.

  6. #6
    Registered User
    Join Date
    Aug 2003
    Posts
    6
    Hey, im new to c++ my self but i thought maybe i could help. :\
    well here goes....
    Code:
    #include <iostream>
    #include <cstdlib>
    using namespace std;
    
    int main(int argc, char *argv[])
    {
    int playGame;
    
    cout<<"\t\t\t\t THE\n";
    cout<<"\t\t\t\tTEMPLE\n";
    cout<<"\t\t\t\t OF\n";
    cout<<"\t\t\t\t TYR\n\n";
    cout<<"1: Play \n";
    cout<<"2: Exit \n";
    cout<<"--> ";
    cin>>playGame;
    
        if (playGame == 1)
        {
            cout<<"Thanks for deciding to play!\n\n";
        }
        if (playGame == 2)
        {
            cout<<"Good bye\n\n";
            system ("PAUSE");
            return 0;
        }
    system ("PAUSE");
    return 0;
    }
    hope that helped.
    Last edited by IznastY; 08-19-2003 at 08:10 PM.

  7. #7
    Veni Vidi Vice
    Join Date
    Aug 2001
    Posts
    343
    That code compiles and runs with no errors. So what īs the problem???

    P.S. Donīt mixed old and new header files. Insteed of
    Code:
    #include <stdlib.h>
    use
    Code:
    #include <cstdlib>
    01000111011011110110111101100100 011101000110100001101001011011100110011101110011 01100100011011110110111001110100 01100011011011110110110101100101 01100101011000010111100101110011 0110100101101110 01101100011010010110011001100101
    Good things donīt come easy in life!!!

  8. #8
    Registered User
    Join Date
    Aug 2003
    Posts
    6
    That code compiles and runs with no errors. So what īs the problem???
    Yeah, his code ran and compiled but it didn't do what he intented it to do.

  9. #9
    Veni Vidi Vice
    Join Date
    Aug 2001
    Posts
    343
    Yeah, his code ran and compiled but it didn't do what he intented it to do.
    Ops, iīve confused your code with Ikurik. Sorry.

    Yourīs code compiles and runs with no problem then .
    P.S. Edit the post to use new header-files.
    01000111011011110110111101100100 011101000110100001101001011011100110011101110011 01100100011011110110111001110100 01100011011011110110110101100101 01100101011000010111100101110011 0110100101101110 01101100011010010110011001100101
    Good things donīt come easy in life!!!

  10. #10
    Registered User
    Join Date
    Aug 2003
    Posts
    17
    What will using the new header files do to the program. After the first or second reply that told me not to use a semicolon at the end of an if statement, everything compiled qnd worked fine

  11. #11
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    Originally posted by Ikurik
    What will using the new header files do to the program. After the first or second reply that told me not to use a semicolon at the end of an if statement, everything compiled qnd worked fine
    follows c99 standard. newer compilers should give backwards warnings for deprecated headers.

  12. #12
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    All of the C++ Standard Library headers are available only 'without the .h' (i.e. <iostream>, <fstream>, <list>, etc).

    The C Standard Library headers are available in both the old C form, and the new C++ form (the only difference being the C++ ones are in the std namespace). So, <stdlib.h>=<cstdlib>, <time.h>=<ctime>, etc.

    Its preferable to use the new style because of the use of the std namespace. Both are valid, however.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  13. #13
    Registered User
    Join Date
    Aug 2003
    Posts
    6
    Oh ok sorry about that, i didn't know about #include <cstdlib>
    , im also pretty new to c++, are there any big differences? because im using devcpp 5 and it adds

    #include <stdlib.h> automatically

  14. #14
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Just the namespace. If you go into environment options though, you can specify what it automatically gives you.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  15. #15
    Registered User
    Join Date
    Aug 2003
    Posts
    6
    Originally posted by Zach L.
    Just the namespace. If you go into environment options though, you can specify what it automatically gives you.
    Cool, thx

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I feel stupid for asking this...
    By applescruff in forum C++ Programming
    Replies: 3
    Last Post: 03-14-2005, 08:49 PM
  2. stupid, stupid question
    By xelitex in forum C++ Programming
    Replies: 5
    Last Post: 12-22-2004, 07:22 PM
  3. Incredibly Stupid People
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 09-09-2003, 04:12 PM
  4. New Stupid...
    By NickESP in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 02-09-2003, 03:41 AM
  5. Stupid over reaction
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 09-30-2001, 08:03 PM

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