Weird Crash

Here is the source code for the little program I am building. Whenever I build/run (code::blocks) it runs perfectly fine inside the IDE. However whenever I compile and run the executable outside the IDE whenever it gets to the "Savings Account Balance" section it will crash after entering any numeral value. Any ideas why it is doing this?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include <cstdlib>
#include <cstdio>
#include <iostream>
using namespace std;
    int inputBalance;
    int savingsBalance;
    int monthlyCalculationQuestion;
    int inputBalanceMonthly;
    string calculateSavingsQuestion;
    void savingsBalanceFunction();
int main(int nNumberofArgs, char* pszArgz[])
{
    cout << "---------------------------------------------------------" << endl;
    cout << "|         This program is an approximation tool.        |" << endl;
    cout << "---------------------------------------------------------" << endl;
    cout << endl;
    cout << "Choose an Option:" << endl;
    cout << endl;
    cout << "1: Bi-Weekly Calculation   " << endl;
    cout << "2: Monthly Calculation     " << endl;
    cout << endl;
    cout << "Option: ";
    cin >> monthlyCalculationQuestion;
    system("CLS");
    if (monthlyCalculationQuestion == 1)
    {
    cout << "---------------------------------------------------------" << endl;
    cout << "|                Bi-Weekly Calculation                  |" << endl;
    cout << "---------------------------------------------------------" << endl;
    cout << endl;
    cout << "Please input your current paycheck." << endl;
    cout << endl;
    cout << "Paycheck Amount: ";
    cin >> inputBalance;
    system("CLS");
        if (inputBalance >= 300)
        {
            cout << "---------------------------------------------------------" << endl;
            cout << "|                Bi-Weekly Calculation                  |" << endl;
            cout << "---------------------------------------------------------" << endl;
            cout << endl;
            cout << "---------------------------------------------------------" << endl;
            cout << "    ITEM               WHAT TO DO WITH IT           TOTAL" << endl;
            cout << "---------------------------------------------------------" << endl;
            inputBalance = inputBalance - 55;
            cout << "After Cigarettes       (Withdrawal -55$)             $" << inputBalance << endl;
            inputBalance = inputBalance - 150;
            cout << "After Gas              (Withdrawal -150$)            $" << inputBalance << endl;
            inputBalance = inputBalance - 100;
            cout << "After Play Money       (Withdrawal -100$)            $" << inputBalance << endl;
            inputBalance = inputBalance - 100;
            cout << "After Cell Bill        (Transfer Savings -100$)      $" << inputBalance << endl;
            inputBalance = inputBalance - 17;
            cout << "After Internet Bill    (Transfer Savings -17$)       $"<< inputBalance << endl;
            cout << endl;
            cout << endl;
            cout << "Would you like to calculate savings? y/n" << endl;
            cin >> calculateSavingsQuestion;
            system("CLS");
            if (calculateSavingsQuestion == "y")
            {
                cout << "---------------------------------------------------------" << endl;
                cout << "|                 SAVINGS CALCULATION                   |" << endl;
                cout << "---------------------------------------------------------" << endl;
                cout << endl;
                cout << "Please enter savings account balance." << endl;
                cout << endl;
                cout << "Balance: ";
                cin >> savingsBalance;
                if (savingsBalance >=0)
                    {
                        savingsBalance = savingsBalance + inputBalance + 117;
                        inputBalance = inputBalance + 117;
                        cout << "Your savings will be up to: $" << savingsBalance << " if you deposit $" << inputBalance << "." << endl;
                    }
                else
                    {
                        cout << "You do not have a savings account but if you deposit " << inputBalance << "you can start one today!" << endl;
                    }
            }
            else
            {
                cout << "Ok. Press any button to close." << endl;
                system("PAUSE");
                return 0;
            }
        }
    }
    else if (monthlyCalculationQuestion == 2)
    {
        {
            cout << "---------------------------------------------------------" << endl;
            cout << "|                Monthly Calculation.                   |" << endl;
            cout << "---------------------------------------------------------" << endl;
            cout << endl;
            cout << "Please input your current paycheck." << endl;
            cout << endl;
            cout << "Paycheck Amount: ";
            cin >> inputBalanceMonthly;
            inputBalanceMonthly = inputBalanceMonthly*2;
            system("CLS");
            if (inputBalanceMonthly >= 600)
            {
                cout << "---------------------------------------------------------" << endl;
                cout << "|                Monthly Calculation.                   |" << endl;
                cout << "---------------------------------------------------------" << endl;
                cout << endl;
                cout << "---------------------------------------------------------" << endl;
                cout << "    ITEM               WHAT TO DO WITH IT           TOTAL" << endl;
                cout << "---------------------------------------------------------" << endl;
                inputBalanceMonthly = inputBalanceMonthly - 110;
                cout << "After Cigarettes       (Withdrawal -110$)            $" << inputBalanceMonthly << endl;
                inputBalanceMonthly = inputBalanceMonthly - 300;
                cout << "After Gas              (Withdrawal -300$)            $" << inputBalanceMonthly << endl;
                inputBalanceMonthly = inputBalanceMonthly - 100;
                cout << "After Cell Bill        (Withdrawal -100$)            $" << inputBalanceMonthly << endl;
                inputBalanceMonthly = inputBalanceMonthly - 17;
                cout << "After Internet Bill    (Withdrawal -17$)             $"<< inputBalanceMonthly << endl;
                inputBalanceMonthly = inputBalanceMonthly - 200;
                cout << "After Play Money       (Withdrawal -200$)            $" << inputBalanceMonthly << endl;
                cout << endl;
                cout << endl;
                cout << "Would you like to calculate savings? y/n" << endl;
                cin >> calculateSavingsQuestion;
                system("CLS");
            if (calculateSavingsQuestion == "y")
            {
                cout << "---------------------------------------------------------" << endl;
                cout << "|                 SAVINGS CALCULATION                   |" << endl;
                cout << "---------------------------------------------------------" << endl;
                cout << endl;
                cout << "Please enter savings account balance." << endl;
                cout << endl;
                cout << "Balance: ";
                cin >> savingsBalance;
                if (savingsBalance >=0)
                    {
                        savingsBalance = savingsBalance + inputBalanceMonthly;
                        cout << "Your savings will be up to: $" << savingsBalance << " if you deposit $" << inputBalanceMonthly << "." << endl;
                    }
                else
                    {
                        cout << "You do not have a savings account but if you deposit " << inputBalanceMonthly << "you can start one today!" << endl;
                    }
            }
        }
    }
    }
    else
    {
        cout << "That is an invalid option please try again \nby relaunching the application." << endl;
    }

}
works fine for me, here. What's probably happening is your program (and therefore the console) is just closing immediately because main is exiting. See this thread for solutions to that problem:

http://cplusplus.com/forum/beginner/1988/
Thanks @Disch such a simple mistake can make a world of a difference xD. The thread didn't work but it did remind me to use this line of code

system("PAUSE");
return 0;

which immediately resolved my issue. Thanks again!
Topic archived. No new replies allowed.