Code runs but nothing happens?

When I run nothing shows up and is immediately exited.
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/****************************************/
//    Preprocessor Directives
/****************************************/
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>

/****************************************/
//            NAMESPACE
/****************************************/
using namespace std;

/*****************************************/
//        GLOBAL VARIABLES
/*****************************************/
int month = 1;


double annual_cc_int_rate,
min_payment_rate,
cc_balance,
interest_to_be_paid,
total_interest_paid,
min_payment;

// Declare ofstream and ifstream
ifstream input_data_file;
string input_file_name = "Lab6.txt";

ofstream output_file;
string output_file_name = "Lab_6_Output.txt";

/*****************************************/
//        FUNCTION PROTOTYPES
/*****************************************/

// get input data from file
void input_data();

void all_calc_functions();

// calculate interest to be paid per month
double calc_int_to_be_paid(double cc_balance);

// calculate minimum payment
double calc_min_payment(double cc_balance, double interest_to_be_paid);

// calculate total interest paid
double calc_total_int_paid(double interest_to_be_paid);

// update balance amount
double update_balance(double interest_to_be_paid);

// show table heading and information inputs
void output_table_heading();

// show table body
void output_table_body();

/********************************************************************************/
//                                    MAIN
/********************************************************************************/

int main()
{

   /********************************************************************/
   //                               INPUT
   /********************************************************************/
   // call function to get information inputs
   input_data();


   /********************************************************************/
   //                               OUTPUT
   /********************************************************************/
   // Open Lab 6 Output.txt
   output_file.open(output_file_name.c_str());

   // call function to display table heading and input
   output_table_heading();

   // Loop to calculate credit card balance
   while (cc_balance >= 0.005)
   {

      //call function to do calculations
      all_calc_functions();

      //call function to display calculation outputs in the table body
      output_table_body();
   }

   // close output and input files
   output_file.close();
   input_data_file.close();

   return 0;
}

/*******************************************************************************/
//                              INPUT FUNCTION
/*******************************************************************************/

void input_data()
{
   // open Lab6.txt
   input_data_file.open(input_file_name.c_str());

   // get credit card balance
   input_data_file >> cc_balance;

   // get annual credit card interest rate
   input_data_file >> annual_cc_int_rate;

   // get minimum payment rate
   input_data_file >> min_payment_rate;
}

/*******************************************************************************/
//                           CALCULATE FUNCTIONS
/*******************************************************************************/
// call all the calculation functions
void all_calc_functions()
{

   // call function that calculates interest amount to be paid
   calc_int_to_be_paid(cc_balance);

   // call the function that calculates minimum payment
   calc_min_payment(cc_balance, interest_to_be_paid);

   // call the function that calculates the total of interest paid
   calc_total_int_paid(interest_to_be_paid);

   // call the function that updates balance amount
   update_balance(interest_to_be_paid);
}
/***************************************************************************/
//             FUNCTION TO CALCULATE INTEREST TO BE PAID
/***************************************************************************/
double calc_int_to_be_paid(double cc_balance)
{
   interest_to_be_paid = cc_balance * ((annual_cc_int_rate / 100) / 12);

   return interest_to_be_paid;
}

/***************************************************************************/
//                 FUNCTION TO CALCULATE MINIMUM PAYMENT
/***************************************************************************/
double calc_min_payment(double cc_balance, double interest_to_be_paid)
{
   min_payment = (cc_balance + interest_to_be_paid) * (min_payment_rate / 100);

   return min_payment;
}

/***************************************************************************/
//                 FUNCTION TO CALCULATE TOTAL INTEREST PAID
/***************************************************************************/

double calc_total_int_paid(double interest_to_be_paid)
{
   total_interest_paid = interest_to_be_paid;

   return total_interest_paid;
}

/***************************************************************************/
//                   FUNCTION THAT UPDATES THE BALANCE
/***************************************************************************/

double update_balance(double interest_to_be_paid)
{
   cc_balance -= interest_to_be_paid;

   return cc_balance;
}



/************************************************************************************/
//                                    OUTPUT
/************************************************************************************/
// show table heading and information inputs
void output_table_heading()
{

   // print information inputs to lab_6_Output.txt
   output_file << setw(27) << right << setprecision(2)
      << showpoint << fixed << "Balance Owing:  " << "$" << cc_balance << endl;

   output_file << setw(21) << right
      << "APR as % " << annual_cc_int_rate << endl;
   output_file << setw(45) << right
      << "Percentage for minimum payment as % " << min_payment_rate << endl;

   output_file << endl
      << setw(52) << right
      << "-------------------------------------------";

   // prints table heading to Lab_6_Output.txt
   output_file << endl << endl
      << "Month"
      << setw(10) << right << "Balance"
      << setw(16) << right << "Interest this month"
      << setw(10) << right << "Minimum"
      << setw(18) << right << "Sum of Interest";

   output_file << endl
      << setw(27) << right << "Month "
      << setw(26) << right << "Paid " << "$";
}
// display table body
void output_table_body()
{

   // display month
   output_file << endl << setw(5) << right << month;

   month++;

   // Set minimum payment to 15.00 if the minimum payment is less than 15.00
   if (min_payment < 15.00)
   {
      min_payment = 15.00;
   }

   // set precision 2 and showpoint
   output_file << setprecision(2) << showpoint << fixed;

   // Display credit card balance, interest to be paid, minimum payment, and total interest paid
   output_file << setw(10) << right << cc_balance
      << setw(16) << right << interest_to_be_paid
      << setw(10) << right << min_payment
      << setw(18) << right << total_interest_paid
      << endl;
}
Are you using an IDE? If so, which one, and can you use the debugger to trace through and watch what happens (a very powerful tool).
Yes I am using VS

The thread 0x2a18 has exited with code 0 (0x0).
'Lab 6 Payment Schedule.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel.appcore.dll'.
Payment Schedule.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcrt.dll'.
Payment Schedule.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rpcrt4.dll'.
Payment Schedule.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sspicli.dll'.
Payment Schedule.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cryptbase.dll'.
Payment Schedule.exe' (Win32): Loaded 'C:\Windows\SysWOW64\bcryptprimitives.dll'.
'Payment Schedule.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sechost.dll'.
The thread 0x498 has exited with code 0 (0x0).javascript:editbox1.editSend()
The thread 0x35c0 has exited with code 0 (0x0).
The thread 0x2854 has exited with code 0 (0x0).
The program '[15708] Payment Schedule.exe' has exited with code 0 (0x0).


Console Output
C:\Users\source\repos\Lab 6 Payment Schedule\Debug\Lab 6 Payment Schedule.exe (process 3680) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .

Last edited on
@Alien000,

Have you looked for your output file?

Lab_6_output.txt?

You program doesn't print any output to the console, so there's nothing for it to show you. It would just run, quite and leave that file behind.

Last edited on
@niccolo it should first ask me to enter rates and balance before sending it to the output file and console does not ask me the questions at all. I tried deleting any file with that name and see if it would start but still doesn't work.
@Alien000

Where in the code you think it should ask a question?

There is nothing in the code that prints out a question or statement (I mentioned this already).

There's nothing in the code that takes input from the console.

No use of cout or cin....so....there's no place for it to ask or take keyboard input.

There is a function "input data", but it takes that input from a file.

It doesn't ask you anything.
Last edited on
I fixed it ROFL TY I'm clueless
:) It's good to know one's strengths and weaknesses
Topic archived. No new replies allowed.