can't run program

This is a discussion on can't run program within the C++ Programming forums, part of the General Programming Boards category; Hey this is my first post here so high everybody! OK, now that greetings are out of the way I ...

  1. #1
    Registered User
    Join Date
    May 2005
    Location
    in your garage
    Posts
    6

    Unhappy can't run program

    Hey this is my first post here so high everybody! OK, now that greetings are out of the way I can tell you guys (or gals) my problem. So, I've compiled everything without error and i can't run my program until I type something and press enter. There is more to the progrm than just typing one thing and I even put 'cin.ignore()' at the end. I'm not sure what to do. (Oh and by the way my program is a text-based game).
    -Arby
    p.s. Here's my code
    Code:
    #include <iostream.h>
    
    using namespace std;
    
    int main()
    {
        int b;
        char string[3];
        //going to make a text game called "Mrs. Jones Pro Student";
        
        
        cout<<"Please enter your initials \n";
        cin.getline ( string, 3, '\n' );
        cout<<"Welcome "<< string<<"!  You are about to begin the exciting adventure of MRS. JONES PRO STUDENT!!!\n"
        "Mrs. Jones is an evil religion teacher at St.Catharine's elementary school.\n"
        "She is obbsesed with making sure that her students keep their shirts tuck in!\n"
        "Are you ready to begin?\n";
        cin>> b;
        if ( b == 1 )
          {cout<<"Than let us begin.\n";}
        else if ( b == 0 )
          {cout<<"THE END\n";}
        else
          {cout<<"I don't understand, please use 1 for yes and 0 for no\n";}
    cin.ignore();
    }
    I know it's a stupid idea me and my friend were high (am I allowed to say that?) when we thought of it but I was bored and decided to do it.
    Last edited by arbiter009; 05-19-2005 at 01:44 PM.

  2. #2
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    maybe posting the code would help

    and try puting
    Code:
    system("PAUSE");
    at the end

    EDIT:

    try
    Code:
    #include <iostream>    // no one uses iostream.h anymore:)
    using namespace std;
    Last edited by mrafcho001; 05-19-2005 at 01:42 PM.

  3. #3
    Registered User
    Join Date
    May 2005
    Location
    in your garage
    Posts
    6
    thank you so much it worked

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,793
    Quote Originally Posted by arbiter009
    can't run program

    So, I've compiled everything without error and i can run my program until I type something and press enter
    Can you or can't you?

    And then...? What happens? What is supposed to happen? Are you doing something like mixing getline with cin?
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  5. #5
    Registered User
    Join Date
    May 2005
    Location
    in your garage
    Posts
    6
    whoops! sorry typo. ?

  6. #6
    Registered User
    Join Date
    May 2005
    Location
    in your garage
    Posts
    6
    It still won't run properly, you can see what's supposed to happen by looking at the source code. With the
    Code:
    system("PAUSE");
    at the end all it does is put everything on screen and skips the cin part.

  7. #7
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    Code:
    #include <iostream>
    #include <stdlib.h>
    #include <string>
    using namespace std;
    
    int main()
    {
        int b = -1;
        string string2;
        //going to make a text game called "Mrs. Jones Pro Student";
        
        
        cout<<"Please enter your initials \n";
        getline ( cin, string2 );
        cout << "Welcome "<< string2<<"!  You are about to begin the exciting adventure of MRS. JONES PRO STUDENT!!!\n";
    	cout << "Mrs. Jones is an evil religion teacher at St.Catharine's elementary school.\n";
        cout << "She is obbsesed with making sure that her students keep their shirts tuck in!\n";
        cout << "Are you ready to begin?\n";
        
    	cin>> b ;
    
        if ( b == 1 )
          {cout<<"Than let us begin.\n";}
        else if ( b == 0 )
          {cout<<"THE END\n";}
        else
          {cout<<"I don't understand, please use 1 for yes and 0 for no\n";}
    	system("PAUSE");
    }
    use string so no matter how much the user types it is all stored

  8. #8
    Registered User
    Join Date
    May 2005
    Location
    in your garage
    Posts
    6
    thank you. that was very helpful.
    *SIDENOTE* do you guys think that this is a stupid idea?
    EDIT: why does b equal -1?

  9. #9
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    Quote Originally Posted by arbiter009
    thank you. that was very helpful.
    *SIDENOTE* do you guys think that this is a stupid idea?
    EDIT: why does b equal -1?

    ops sorry about that... i was just messing around i had an unusual bug.

    not a good idea.

    well it really doesn't matter.. it will get overwriten, so..

  10. #10
    Registered User
    Join Date
    May 2005
    Location
    in your garage
    Posts
    6
    yeah i know it's not a good idea but my friend told that he would pay me to do it and we were high so whatever.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 02:30 PM
  2. Re-doing a C program to run in Win2000 or XP
    By fifi in forum C Programming
    Replies: 5
    Last Post: 08-17-2007, 05:32 PM
  3. Replies: 3
    Last Post: 07-11-2005, 03:07 AM
  4. plz help me run this program!!!
    By galmca in forum C Programming
    Replies: 8
    Last Post: 02-01-2005, 12:00 PM
  5. Cannot run program in background?
    By registering in forum Linux Programming
    Replies: 3
    Last Post: 06-16-2003, 05:47 AM

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