Thread: Program closes too early

  1. #1
    Registered User MoonMan's Avatar
    Join Date
    Nov 2011
    Posts
    19

    Question Program closes too early

    So when I build and run this program IN CodeBlocks it runs through the whole thing fine..

    When I build a Release and load it from the executable it stops and closes the program out immediately after selecting 1 or 2 for incomechoice.. Any help is much appreciated...Thank you

    Code:
    while ( t < 1 )
    
    {
    
        {
        cout<<"\n\nIs there any bills/expenses we missed?\n";
        cout<<"Please make sure we haven't left anything out.\n";
        cout<<"\nEnter the corresponding number below\n";
        cout<<"\nYes(1) No(2): ";
        cin>> missedchoice;
        cin.get();
        }
    
        if ( missedchoice == 1 )
        {
        cout<<"\nPlease input your missed expense on a MONTHLY calculation: ";
        cin>> missedinput;
        cin.get();
        t = t + 1;
        }
    
        else if ( missedchoice == 2 )
        {
        t = t + 1;
        }
    
        else if ( missedchoice > 2 )
        {
        cout<<"\n\n\n\n  Invalid entry.  Please enter 1 or 2.\n\n";
        t==0;
        }
    
    }
    
    //End missed expense check
    
    //Begin calculations Hourly
    
    if ( missedchoice == 1 )
        {
        cout<<"\n\nCalculating...\n";
        cout<<"Calculating.....\n";
        cout<<"Calculating.......\n";
        cout<<"Calculating........\n";
        cout<<"\n\n\nYour net pay for the year should be around:  $"<< paycheck * 52 <<"\n\n\n";
        cout<<"          AFTER EXPENSES YOU WILL HAVE:";
        cout<<"\n\n$"<< ( paycheck * 52 / 12 ) - ( annual / 12 ) - ( gas * 52 / 12 ) - ( food * 52 / 12 ) - ( expenses ) - ( missedinput )<<"/MONTH\n";
        cout<<"\n\n$"<< ( paycheck ) - ( annual / 52 ) - ( gas ) - ( food ) - ( expenses * 12 / 52) - ( missedinput * 12 / 52)<<"/WEEK";
        cout<<"\n\n\n$"<< ( paycheck * 52 / 365 ) - ( annual / 365 ) - ( gas * 52 / 365 ) - ( food * 52 / 365 ) - ( expenses * 12 / 365 ) - ( missedinput * 12 / 365 )<<"/DAY";
        u = u + 1;
        }
    
    
    else if ( missedchoice == 2 )
        {
        cout<<"\n\nCalculating...\n";
        cout<<"Calculating.....\n";
        cout<<"Calculating.......\n";
        cout<<"Calculating........\n";
        cout<<"\n\n\n\nYour net pay for the year should be around:  $"<< paycheck * 52 <<"\n\n\n";
        cout<<"          YOUR MONEY AFTER EXPENSES WILL BE:";
        cout<<"\n\n$"<< ( paycheck * 52 / 12 ) - ( annual / 12 ) - ( gas * 52 / 12 ) - ( food * 52 / 12 ) - ( expenses )<<"/MONTH\n";
        cout<<"\n\n$"<< ( paycheck ) - ( annual / 52 ) - ( gas ) - ( food ) - ( expenses * 12 / 52)<<"/WEEK";
        cout<<"\n\n\n$"<< ( paycheck * 52 / 365 ) - ( annual / 365 ) - ( gas * 52 / 365 ) - ( food * 52 / 365 ) - ( expenses * 12 / 365 )<<"/DAY";
        u = u + 1;
        }
    
    //End Hourly Calc
    
    if ( ( ( paycheck * 52 / 365 ) - ( annual / 365 ) - ( gas * 52 / 365 ) - ( food * 52 / 365 ) - ( expenses * 12 / 365 ) ) < 0 )
        {
        cout<<"\nHmmm, either we messed up somehwere or you have some debt.\n\n";
        }
    
      //END
    
    
        {
            cout<<"\n\n                       Thank you for using Liquid Money!\n\n\n\n";
        }
    
    }

  2. #2

  3. #3
    Registered User
    Join Date
    Dec 2011
    Posts
    4
    Can't you just place a getchar() function at the end of your code. Your program is that your program runs so fast that no can't see it. I would put the getchar() function at the end of the code just to test if that will keep the program from running and just disappearing.

  4. #4
    Registered User MoonMan's Avatar
    Join Date
    Nov 2011
    Posts
    19
    Quote Originally Posted by Rodrigues123 View Post
    Can't you just place a getchar() function at the end of your code. Your program is that your program runs so fast that no can't see it. I would put the getchar() function at the end of the code just to test if that will keep the program from running and just disappearing.
    I think you are right but I get an error now that getchar was not declared in this scope.. I placed it where line 81 is in the code up top... Sorry I am brand new to this... Thank you for the help

  5. #5
    Registered User MoonMan's Avatar
    Join Date
    Nov 2011
    Posts
    19
    EDIT: Got it, had to use the cin.get()...Is this pretty much the same function as getchar()?
    Last edited by MoonMan; 12-11-2011 at 03:50 PM.

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Yep. C++ equivalent.
    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. Program closes too early
    By RebekahNicole in forum C Programming
    Replies: 7
    Last Post: 03-08-2011, 12:46 PM
  2. Program closing early?
    By darren78 in forum C++ Programming
    Replies: 5
    Last Post: 05-01-2010, 03:02 AM
  3. Program closes when startup form closes
    By dcboy in forum C# Programming
    Replies: 1
    Last Post: 07-01-2006, 02:40 AM
  4. Early program stop problem
    By bmb_ksu in forum C Programming
    Replies: 9
    Last Post: 02-19-2006, 09:24 AM
  5. making a program leave a msg for background program when it closes
    By superflygizmo in forum Windows Programming
    Replies: 2
    Last Post: 02-06-2006, 07:44 PM