My program is acting differently when I run it in my compiler than when I build it

This is a discussion on My program is acting differently when I run it in my compiler than when I build it within the C++ Programming forums, part of the General Programming Boards category; Okay, so this is really weird. I'd just finished up a good chunk of program in my compiler (I use ...

  1. #1
    Registered User
    Join Date
    Jul 2012
    Posts
    36

    My program is acting differently when I run it in my compiler than when I build it

    Okay, so this is really weird.

    I'd just finished up a good chunk of program in my compiler (I use code::blocks) and tested it out by hitting compile. It worked perfectly well, the following loop statement:

    Code:
     while (player_choices.tutorial_choice_seven != 1)
        {
            cout << "The mare nods, \"Okay then, let's get you to the stallion in charge.\" \n1. Okay, let's do it!\n2. Can I ask you some questions first? \n\n";
            cout << "Choose an option: \n";
            cin >> player_choices.tutorial_choice_seven;
            switch (player_choices.tutorial_choice_seven)
            {
                case 1:
                cout << "\"Allright then, time to meet the people you saved.\"\n\n";
                cout << "End Tutorial. Wind's oppinion of you is: ";
                if (wind_opinion_reference == 0)
                {
                    cout << "FAVORABLE\n\n";
                }
                if (wind_opinion_reference == 1)
                {
                    cout << "SLIGHTLY FAVORABLE\n\n";
                }
                if (wind_opinion_reference == 2)
                {
                    cout << "NEUTRAL\n\n";
                }
                cout << "Press any key to exit.\n\n";
                break;
                case 2:
                cout << "Fire away.\n\n";
                game_characters.wind_conversation_one(wind_conversation_choice_one_reference);
                break;
            }
        }
        cout << "Thank's for playing!";
        cin.get();
    }
    executed as written, but when I built the .exe file and ran it everything worked fine right up until the end where I entered one and the program closed before displaying any of the information from the if statement or either of the if independent cout statements. In short, it was acting fundamentally different from when I ran it in the compiler even though I entered the same choices.

    I honestly have no idea what would cause this, has it happened to anyone here? I would be extremely grateful for any assistance.

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,246
    The IDE is helping you out by keeping the window open after the program terminates. That is NOT the normal behavior -- normally a console app window goes away the moment the program exits.

    (The reason the program is terminating, even though you have a cin.get(), is because you are not using cin.ignore() properly. There is a FAQ on this, though I don't remember where it is)
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    Registered User
    Join Date
    Jul 2012
    Posts
    36
    Quote Originally Posted by brewbuck View Post
    The IDE is helping you out by keeping the window open after the program terminates. That is NOT the normal behavior -- normally a console app window goes away the moment the program exits.

    (The reason the program is terminating, even though you have a cin.get(), is because you are not using cin.ignore() properly. There is a FAQ on this, though I don't remember where it is)
    You're a good person and you should feel good! Thank you! It's fixed!
    I really do need to learn how to do cin.ignore() I guess.

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,667
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I need to build web site with c++ compiler
    By mnoooor in forum C++ Programming
    Replies: 8
    Last Post: 10-24-2010, 11:55 AM
  2. Is my compiler acting up?
    By Alastor in forum C Programming
    Replies: 10
    Last Post: 10-11-2005, 07:19 PM
  3. compiler build error
    By KristTlove in forum C++ Programming
    Replies: 2
    Last Post: 11-30-2003, 09:16 AM
  4. lol, funniest acting program EVER -- and i need help with it :(
    By Leeman_s in forum Windows Programming
    Replies: 1
    Last Post: 01-09-2003, 06:27 PM
  5. Break And Build Program
    By HaroBoy09 in forum C++ Programming
    Replies: 1
    Last Post: 12-07-2001, 01:03 PM

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