Error in Functions

I've been working on a program that has me create functions, but I seemed to have messed up my code in the If/else statements. Also, I'm not sure how to identify a term or the best way to output a result. Here are my questions.

1. What am I doing wrong with the if/else statements of the while loop and void Printreport?
2. How should I declare Eligible? Using string won't work. Eligible needs to be type boolean.
3. The result output needs to list the type of loan being applied for, but short of typing out four possible output statements, is there a better way to define which loan type it is and reference the loan type in the cout statement?

Here is the code. Thank you for any and all help.

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
#include <iostream>	// for cout, endl
#include <string>
using namespace std;

//Function Prototypes

void Getinput(int& Loantype, float& Income, float& Totaldebt, float& Loanamount);
void Autoloan(float& Income, float& Totaldebt, float& Loanamount, string Eligible);
void Mortgage(float& Income, float& Totaldebt, float& Loanamount, string Eligible);
void Printreport(int& Loantype, float& Loanamount, string Eligible);

void main ()
{
	int Loantype;
	float Income, Totaldebt, Loanamount;

	while(Loantype != 3)
		{Getinput(Loantype, Income, Totaldebt, Loanamount);
			if(Loantype == 1);
				{Autoloan (Income, Totaldebt, Loanamount, Eligible);
		Printreport (Loantype, Loanamount, Eligible);}
	else 
		if(Loantype == 2);
	{Mortgage (Income, Totaldebt, Loanamount, Eligible);
	 Printreport (Loantype, Loanamount, Eligible);
	//*********************************************

	void Getinput(int& Loantype, float& Income, float& Totaldebt, float& Loanamount);
	{
		cout << "Select one of the following options:" << endl << endl;
		cout << "	1	Auto Loan" << endl;
		cout << "	2	Home Mortgage Loan" << endl;
		cout << "	3	Stop Program" << endl << endl;
		cout << "Enter a number." << endl;
		cin >> Loantype;
		if (Loantype == 1 || Loantype == 2)
			{cout << "Enter Income, Total Debt, and Loan Amount." << endl;
			cin >> Income >> Totaldebt >> Loanamount;
		}
	}


	 //************************************************

	 void Autoloan(float& Income, float& Totaldebt, float& Loanamount, string Eligible);
	 {
		if (Income - Totaldebt >= Loanamount * .5)
			Eligible = true;
		else Eligible = false;
	 }

	 //***********************************************

	 void Mortgage(float& Income, float& Totaldebt, float& Loanamount, string Eligible);
	 {
		 if (Income - Totaldebt >= Loanamount * .3)
			 Eligible = true;
		 else Eligible = false;
	 }

	 //***********************************************

	void Printreport(int& Loantype, float& Loanamount, string Eligible);
	{
		if (Eligible = true);
		cout << "Loan Type: " << endl;
		cout << "Loan Amount: " << Loanamount << endl;
		cout << "Eligible: Yes." << endl; 
		else 
			if (Eligible = false);
				cout << "Loan Type: " << endl;
				cout << "Loan Amount: " << Loanamount << endl;
				cout << "Eligible: No." << endl;
	}
	}}
The first two questions are fairly simple.

In your if/else statements your syntax was incorrect. You do not want to put a semicolon at the end of the control statement, and you need to use brackets. You also don't need the extra if statement on line 70. For example, lines 65-73 should look like this:

if (Eligible == true)
{
cout << "Loan Type: " << endl;
cout << "Loan Amount: " << Loanamount << endl;
cout << "Eligible: Yes." << endl;
}
else
{
cout << "Loan Type: " << endl;
cout << "Loan Amount: " << Loanamount << endl;
cout << "Eligible: No." << endl;
}

Fix all of your if/else statements and those should work fine.

For question 2, booleans are declared using variable type bool. For example,
bool Eligible;

I'm a little unsure what you're asking for question 3.
Last edited on
Thank you for the help so far. The third question refers to the Printreport function. Since the output needs to display the type of loan (Auto or Mortgage) but the loan type is selected based on the number, what would be the most effective way to list the loan type? Should I use a reference or write four if statements, one for each potential answer: Auto-Yes, Auto-No, Mortgage-Yes, and Mortgage-No?
Any help on the the third question?
The most efficient way to do this would probably be as follows:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void Printreport(int& Loantype, float& Loanamount, bool Eligible);
{
      cout << "Loan Type: " << endl;
      If (Loantype == 1)
      {
            cout << "Auto loan";
      }
      else
      {
            cout << "Mortgage loan";
      }
      cout << "Loan Amount: " << Loanamount << endl;
      if (Eligible = true)
      {
            cout << "Eligible: Yes." << endl;
      }
      else
      {
            cout << "Eligible: No." << endl;
      }
}

Sorry I took so long. I've been at school. I hope your still checking these posts. If your code doesn't work after these changes post the revised code to go from there.
Last edited on
Topic archived. No new replies allowed.