Frustrating problem with if statement using booleans

I cannot figure out why my program does not catch the last part!
So the function asks for 2 inputs, and then after those it should ask for a bool answer (whether the annual rate is known or not) it does that fine, and works down to the function void print_payment_table_header (bool bool_par) (line 105) For some reason it does not catch the if statement in there. I will always output the cout as if the bool expression where true. I know that the code is not complete yet but i am waiting on one equation to come in to finish it up and i cant figure this part out in the mean time. I am sure it is a really obvious mistake that iam just overlooking or something. Thanks in advance.
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
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

void get_input (double& principal_par, double& loan_length_par, bool& interest_known_par, double& interest_rate_par);
void utility (double& monthly_interest_par, double interest_util_par, double loan_length_util_par, double& number_of_months_par);
double monthly_payment (double p_par, double j_par, double n_par);
void print_monthly_rates (double princ_par, double j_par, double m_par, double& h_par, double& q_par, double& c_par, bool bool_par);
void print_payment_table_line (double h_par, double c_par, double q_par);
void print_payment_table_header (bool bool_par);
void print_possible_monthly_payments (double q_par, double c_par);

int main ()
{

	double p, l, r, j, n, h, c, q, m;	
	bool k = false;

	get_input (p, l, k, r);
	utility (j, r, l, n);
	m = monthly_payment (p, j, n);	
	print_monthly_rates (p, j, m, h, q, c, k);

	return 0;
}

void get_input (double& principal_par, double& loan_length_par, bool& interest_known_par, double& interest_rate_par)
{
	char interest_known_answer;
	cout << "Please enter the principal: ";
	cin >> principal_par;
	cout << "Please enter the length of the loan (in YEARS): ";
	cin >> loan_length_par;
	cout << "Is the annual interest rate known? ";
	cin >> interest_known_answer;
	if ((interest_known_answer == 'y') || (interest_known_answer == 'Y'))
	{
		interest_known_par = true;
		cout << "Please enter the annual interest rate: ";
		cin >> interest_rate_par;
	}	
	else
	{	
		interest_known_par = false;
	}	
}

void utility (double& monthly_interest_par, double interest_util_par, double loan_length_util_par,  double& number_of_months_par)
{
	monthly_interest_par = (interest_util_par / (12*100));
	number_of_months_par = (loan_length_util_par * 12);
}

double monthly_payment (double p_par, double j_par, double n_par)
{
	double m = p_par * (j_par / (1 - pow((1 + j_par),(-n_par))));

	return (m);
}

void print_monthly_rates (double p_par, double j_par, double m_par, double& h_par, double& q_par, double& c_par, bool bool_par)
{
	if (bool_par == true)
	{
		cout << "\nMonthly Payment: " << m_par << "$" << endl << endl;
		print_payment_table_header (bool_par);

		do {
		
			h_par = p_par * j_par;
	
			c_par = m_par - h_par;

			q_par = p_par - c_par;
	
			p_par = q_par;
			if (p_par < 0)
			{
				p_par = 0;
			}
			
			print_payment_table_line (h_par, c_par, q_par); 

		} while (q_par >0);
	}
	
	else
	{
		print_payment_table_header (bool_par);
		print_possible_monthly_payments (q_par, c_par);
	}
}

void print_payment_table_line (double h_par, double c_par, double q_par)
{
	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(2);
	cout << setw(10) << h_par;
	cout << setw(30) << c_par;
	cout << setw(40) << q_par << endl;
}

void print_payment_table_header (bool bool_par)
{
	cout << setw(55);
	cout << "Mortgage Payment Table" << endl;
	cout << setw(0);
	cout << "------------------------------------------------------------------------------------------\n";
	if (bool_par = true)
	{
		cout << setw(90);
		cout << "Monthly Interest    ||    Principal payment of the month    ||    New principal balance\n";
	}
	
	else 
	{
		cout << setw(51);
		cout << "FIXED MONTHLY PAYMENT    ||    Interest Rates\n";
	}
}

void print_possible_monthly_payments (double q_par, double c_par)
{
	for (double i = 3.5; i >= 5; i += .25)
	{
		cout << setw(7);
		double fixed_monthly_payment = q_par * c_par;
		cout << fixed_monthly_payment;

		cout << setw(40);
		cout << i;
	}
}
if (bool_par = true)

Don't you mean ==? And don't feel bad, we all had to go through this at least once in our lives.

PS: You can leave the comparison completely out. A bool is already a boolean expression.
Last edited on
omg your a genius! thank you so much. its been a long day :(
Topic archived. No new replies allowed.