cout not working after While statement

Feel free to critic any part of the code, but the problem im having is that the cout at the end is not working after the while statement.

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


#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

// Brenton White 

int main()
{
	// User Input
	double account;  // Patient account number
	int day, month, year;	 // Consultation date
	double tfee;     // Treatment fee
	double ipayment; // Initial payment
	double mpayment;  // Monthly payment 
					  // Program output
	double balance; // Balance due tfee - ipayment
	int paymentn; // Payment number
	paymentn = 1;
	int monthdue; // Due date month
	double totalp; // Total paid


				  // input
	cout << "\n\n\n\n";

	cout << "\n    Enter Patient Account Number: ";
	cin >> account;
	cout << "\n        Enter Consultation Date **/**/**** ";
	cout << "\n\n    Day: ";
	cin >> day;
	cout << "\n    Month: ";
	cin >> month;
	cout << "\n    Year: ";
	cin >> year;

	cout << "\n    Enter Treatment Fee: ";
	cin >> tfee;
	cout << "\n    Enter Initial Payment: ";
	cin >> ipayment;
	cout << "\n    Enter Monthly Payment: ";
	cin >> mpayment;

	// -------
	balance = tfee - ipayment; // Ballance
	monthdue = month + 1; // Add 1. = 1st month of mpayments
	paymentn = 1; // payment number 
	

	// Output
	
	cout << "\n\n\n\n";
	cout << "    Patient Account Number: " << setw(2) << account << endl;
	cout << "    Consulation Date: ";
	cout << day << "/";
	cout << month << "/";
	cout << year << "\n";

	cout << setprecision(2) << fixed;
	cout << "\n\n";
	cout << "    Treatment Fee: " << setw(62) << tfee << endl;
	cout << "    Initial Payment: " << setw(60) << ipayment << endl;
	cout << "    Balance Due: " << setw(64) << balance << endl;

	cout << "\n";
	cout << "        Payment Number";
	cout << "        Due Date";
	cout << "        Payment Amount";
	cout << "        Total Paid";
	cout << "        Oustanding Balance";
	cout << "\n\n";

	while (monthdue > 0)
	{
		
		while (balance >= 0)
		{
			
			if (balance > 0)
			{
				if (balance < mpayment)
					mpayment = balance;
			}

			if (monthdue > 12)
			{
				year = year + 1;
				monthdue = 1;
			}

		
			
		totalp = tfee - balance; // total paid

		cout << setprecision(0) << fixed;
		// Payment Number
		cout << "            " << setw(4) << paymentn;
		// Due Date
		cout << "             ";
		cout << setw(2) << setfill('0') << day << "/";
		cout << setw(2) << setfill('0') << monthdue << "/";
		cout << year;
		// Payment Amount
		cout << setprecision(2) << fixed;
		cout << "          " << setw(7) << setfill(' ') << mpayment;
		// Total Paid
		cout << "            " << setw(7) << setfill(' ') << totalp;
		// Outstanding Balance
		cout << "                 " << setw(7) << setfill(' ') << balance;
		cout << endl;

		balance = balance - mpayment;
		paymentn += 1;

		monthdue = monthdue + 1;
		


		}

		
	}

	
		cout << "\n\n";
		cout << " ******************** Payment Schedule Printed By: Brenton White ******************** ";
		cout << "\n\n\n\n";

	

	return 0;
}

Its because the program never exits out of your nested while loop. While the "monthdue" and "balance" is greater than 0 it will continue executing. This is why your "cout" isn't called.
Last edited on
Maybe you can try something like 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

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

// Brenton White 
bool close = false;

int main()
{
	// User Input
	double account;  // Patient account number
	int day, month, year;	 // Consultation date
	double tfee;     // Treatment fee
	double ipayment; // Initial payment
	double mpayment;  // Monthly payment 
					  // Program output
	double balance; // Balance due tfee - ipayment
	int paymentn; // Payment number
	paymentn = 1;
	int monthdue; // Due date month
	double totalp; // Total paid


				   // input
	cout << "\n\n\n\n";

	cout << "\n    Enter Patient Account Number: ";
	cin >> account;
	cout << "\n        Enter Consultation Date **/**/**** ";
	cout << "\n\n    Day: ";
	cin >> day;
	cout << "\n    Month: ";
	cin >> month;
	cout << "\n    Year: ";
	cin >> year;

	cout << "\n    Enter Treatment Fee: ";
	cin >> tfee;
	cout << "\n    Enter Initial Payment: ";
	cin >> ipayment;
	cout << "\n    Enter Monthly Payment: ";
	cin >> mpayment;

	// -------
	balance = tfee - ipayment; // Ballance
	monthdue = month + 1; // Add 1. = 1st month of mpayments
	paymentn = 1; // payment number 


				  // Output

	cout << "\n\n\n\n";
	cout << "    Patient Account Number: " << setw(2) << account << endl;
	cout << "    Consulation Date: ";
	cout << day << "/";
	cout << month << "/";
	cout << year << "\n";

	cout << setprecision(2) << fixed;
	cout << "\n\n";
	cout << "    Treatment Fee: " << setw(62) << tfee << endl;
	cout << "    Initial Payment: " << setw(60) << ipayment << endl;
	cout << "    Balance Due: " << setw(64) << balance << endl;

	cout << "\n";
	cout << "        Payment Number";
	cout << "        Due Date";
	cout << "        Payment Amount";
	cout << "        Total Paid";
	cout << "        Oustanding Balance";
	cout << "\n\n";

	while (monthdue > 0)
	{

		while (balance >= 0)
		{

			if (balance > 0)
			{
				if (balance < mpayment)
					mpayment = balance;
			}

			if (monthdue > 12)
			{
				year = year + 1;
				monthdue = 1;
			}



			totalp = tfee - balance; // total paid

			cout << setprecision(0) << fixed;
			// Payment Number
			cout << "            " << setw(4) << paymentn;
			// Due Date
			cout << "             ";
			cout << setw(2) << setfill('0') << day << "/";
			cout << setw(2) << setfill('0') << monthdue << "/";
			cout << year;
			// Payment Amount
			cout << setprecision(2) << fixed;
			cout << "          " << setw(7) << setfill(' ') << mpayment;
			// Total Paid
			cout << "            " << setw(7) << setfill(' ') << totalp;
			// Outstanding Balance
			cout << "                 " << setw(7) << setfill(' ') << balance;
			cout << endl;

			balance = balance - mpayment;
			paymentn += 1;

			monthdue = monthdue + 1;
		
			close = true;
		
			if (close)
			{
				cout << "\n\n";
				cout << " ******************** Payment Schedule Printed By: Brenton White ******************** ";
				cout << "\n\n\n\n";

				cin.get();
				cin.get();
				return 0;
			}

		}

		
	}


	


	
	return 0;
}
Last edited on
I had a palm to face moment. realized that the "while (monthdue > 0)" Statement was useless. the while statement is supposed to end when the balance hits 0. still wouldnt mind some critic, but the question is solved.
Topic archived. No new replies allowed.