Looking for some valuable help

Hello guys, I am new to C++ and a complete novice. I have no clue what I am doing but have attempted to make the following Loan Calculator using Classes and Objects. I have looked at on-line tutorials and purchased a couple of books but I am stuck with getting a output.

Please could someone have a look over my code and advise me on how to do this?

Sorry if I have posted this in the wrong area, many thanks in advanced :)

#include "stdafx.h"
#include <iostream>
#include <string>/
#include <conio.h>

using namespace std;

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
242
243
244
245
246
247
248
249
250
class LoanDetails 
{
public:
	void Set_dLoanType(double dTypeTemp)  
	{
		dLoanType = dTypeTemp;  
	}
	void Set_dLoanLength(double dLengthTemp)
	{
		dLoanLength = dLengthTemp; 
	}
	void Set_dLoanAmount(double dAmountTemp)
	{
		dLoanAmount = dAmountTemp; 
	}
	double Get_dLoanAmount()
	{
		return dLoanAmount; 
	}
	double Get_dLoanLength()
	{
		return dLoanLength;
	}
	double Get_LoanType()
	{
		return dLoanType;
	}
public:// Seen by everyone
	double dLoanType = 0; 
	double dLoanLength = 0;
	double dLoanAmount = 0; 
};

class CustomerDetails 
{
public:
	void Set_sCustomerName(string sNameTemp)
	{
		sCustomerName = sNameTemp; 
	} 
	void Set_dCustomerAge(double dAgeTemp)
	{
		dCustomerAge = dAgeTemp; 
	} 
	void Set_dCustomerSalary(double dSalaryTemp)
	{
		dCustomerSalary = dSalaryTemp; 
	} 
	string Get_CustomerName()
	{
		return sCustomerName;
	}
	double SetCustomerAge()
	{
		return dCustomerAge;
	} 
	double SetCustomerSalary()
	{
		return dCustomerSalary; 
	} 

public: // seen by all classes
	string sCustomerName = ""; 
	double dCustomerAge = 0; 
	double dCustomerSalary = 0;
};

class APR
{
public:// Seen by everyone
	double dRate1 = 4.9; // set the default value 
	double dRate2 = 3.9; // set the default value 
	double dRate3 = 29.9; // set the default value 
};

class APRCalculator :public LoanDetails, public APR 
{
public:// seen by all classes
	double GetMonthlyTotal() 
	{
		return (dLoanAmount + (dLoanAmount * (dRate3 / 100))); 
	}
	double GetYearlyTotal1()
	{
		return (dLoanAmount + (dLoanAmount * (dRate2 / 100))); 
	}
	double GetYearlyTotal2()
	{
		return (dLoanAmount + (dLoanAmount * (dRate1 / 100))); 
	}
};

int main()
{
	APRCalculator objCalculator;
	objCalculator.dLoanAmount;
	objCalculator.dLoanLength;
	objCalculator.dRate1;
	objCalculator.dRate2;
	objCalculator.dRate3;

	CustomerDetails objCustomerDetails; 
	LoanDetails objLoanDetails;

	string sCustomerName = ""; 
	double dCustomerAge = 0;
	double dCustomerSalary = 0;
	double dLoanLength = 0;
	double dLoanAmount = 0;
	double dLoanTpe = 0;
	double dAPR = 0;
	double dRate1 = 4.9;

	char pound = 156; 

	cout << " -----Loan Calculator----- \n\n"; 
	cout << "Loan Type:";
	cout << "\n"; 
	cout << " 1. long Term - Standard - 3-5 Years - APR 4.9% - Max Loan " << pound << "40,000";
	cout << "\n";
	cout << " 2. long Term - Standard - 1-2 Years - APR 3.9% - Max Loan " << pound << "12,000";
	cout << "\n";
	cout << " 3. Emergency - Short - 1-6 Monhs - APR 29.9% - Max Loan " << pound << "3,000";
	cout << "\n";
	cout << "\n";  

	cout << "To Qualify For:";
	cout << "\n";
	cout << " # long Term - Age - 21+ Years - Income Per Year " << pound << "24,000";
	cout << "\n";
	cout << " # short Term - Age - 18+ Years - Income Per Year " << pound << "21,000";
	cout << "\n";
	cout << " # Emergency - Age - 18+ Years - Income Per Year " << pound << "12,000";
	cout << "\n";
	cout << "\n"; // The above text is displayed at the top of the program

	do 
	{
		cout << "Enter Age:";
		cin >> dCustomerAge;
		objCustomerDetails.Set_dCustomerAge(dCustomerAge);
		cout << "\n";

		if (cin.fail() == true)
		{
			cout << "Incorrect input, Numbers only \n";
			std::cin.clear();
			cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
		}

		else
		{
			if (dCustomerAge < 18)
			{
				cout << "You're too young, Sorry\n\n";
			}
			else
			{
				objCustomerDetails.Set_dCustomerAge(dCustomerAge);
				cout << "\n";
			}
		}

	} while (dCustomerAge < 18);

		cout << "Enter Name:";
		cin >> sCustomerName;
		objCustomerDetails.Set_sCustomerName(sCustomerName);
		cout << "\n";

			cout << "Enter salary:" << pound;
			cin >> dCustomerSalary;
			objCustomerDetails.Set_dCustomerSalary(dCustomerSalary);
			cout << "\n";

			if (dCustomerSalary <= 11999)
			{
				cout << "You do not earn enough.";
			}
			else
					if (dCustomerSalary >= 12000 && dCustomerSalary < 19999)
					{
						cout << "You are allowed the following loan: \n\n";
						cout << "3. Emergency - Short - 1 - 6 Months - APR 29.9% -Max Loan \n\n";
						cout << "Enter Amount:" << pound;


						if (cin.fail() == true)
						{
							cout << "Incorrect input, Numbers only \n";
							std::cin.clear();
							cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
						}


						cin >> dLoanAmount;
						objLoanDetails.Set_dLoanAmount(dLoanAmount);
						cout << "\n";

					cout << "Enter Length:";
					cin >> dLoanLength;
					objLoanDetails.Set_dLoanLength(dLoanLength);
					cout << "\n";
				}

		if (dCustomerSalary >= 21000)
		{
			cout << "You are allowed the following loan \n\n";
			cout << "2. long Term - Standard - 1 - 2 Years - APR 3.9% -Max Loan \n\n";
			cout << "3. Emergency - Short - 1 - 6 Monhs - APR 29.9% -Max Loan \n\n";
			cout << "Enter Amount \n\n ";
			cin >> dLoanAmount;
			objLoanDetails.Set_dLoanAmount(dLoanAmount);
			cout << "\n";
			cout << "Enter Length \n\n";
			cin >> dLoanLength;
			objLoanDetails.Set_dLoanLength(dLoanLength);
			cout << "\n";
			cout << "Total Monthly";
		}

		if (dCustomerAge >= 21)
		{
			if (dCustomerSalary >= 24000)
			{
				cout << "You are allowed the following loan \n\n";
				cout << " 1. long Term - Standard - 3-5 Years - APR 4.9% - Max Loan \n\n";
				cout << "2. long Term - Standard - 1 - 2 Years - APR 3.9% -Max Loan \n\n";
				cout << "3. Emergency - Short - 1 - 6 Monhs - APR 29.9% -Max Loan \n\n";
				cout << "Enter Amount \n\n ";
				cin >> dLoanAmount;
				objLoanDetails.Set_dLoanAmount(dLoanAmount);
				cout << "\n";
				cout << "Enter Length \n\n";
				cin >> dLoanLength;
				objLoanDetails.Set_dLoanLength(dLoanLength);
				cout << "\n";
				cout << "Total Monthly";
			}
		}


	cout << "Total loan cost:" << objCalculator.GetMonthlyTotal();
	cout << "\n";

	_getch();

	return 0;
}
Last edited on
Hey and welcome. Please edit your post and use code tags to make code readable - http://www.cplusplus.com/articles/jEywvCM9/

It would also help if you could ask more specific questions, what is the actual problem, are you getting errors? If so please post the complete error messages. Is something not right? Tell us what it is =)

Sorry, I am new, please forgive me. I will edit the code straight away.

I am not getting errors. The program runs but does nothing lol. I would like it to calculate a Loan that a customer wants. However I have no clue how to do this. I was just looking for some advice or tips.

Apologies again :)
Topic archived. No new replies allowed.