Function program gives no errors.

I have typed up this entire program which should give users a menu option that allows them to determine loan eligibility. It displays 3 options at the menu, with option 3 ending the program. The program is a loop with functions, and selection option 3 ends the loop. However, Visual 2010 gives me no code errors but won't compile. Does anyone see what's wrong with this code? Any help is greatly appreciated.

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
#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, bool Eligible);
void Mortgage(float& Income, float& Totaldebt, float& Loanamount, bool Eligible);
void Printreport(int& Loantype, float& Loanamount, bool Eligible);

void main ()
{
	int Loantype;
	float Income, Totaldebt, Loanamount;
	bool Eligible;
	string Loantype2;

	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;
		}
	}
	
	if (Loantype = 1)
			Loantype2 = "Auto";
		else if (Loantype = 2)
			Loantype2 = "Mortgage";


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

	 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: " << Loantype2 << endl;
			cout << "Loan Amount: " << Loanamount << endl;
			cout << "Eligible: Yes." << endl;}
		else 
			{
			cout << "Loan Type: " << Loantype2 << endl;
			cout << "Loan Amount: " << Loanamount << endl;
			cout << "Eligible: No." << endl;}
	}
	}
You can start by using int main() and not void main().
They are all good in VS only int is the only true C++ way.

1) Some of the '{' and '}' are in the wrong places.
2) All the ';' after the function definitions need to be removed.
3) Every time you want to compare in a if statement you need to use '==' not '='.
'A = B' is telling that A is B and 'A == B' is asking IF A is B.

After I fixed all this I got the errors:
- ‘Loantype2’ was not declared in this scope
- ambiguous overload for ‘operator=’ in ‘Eligible = false’
1
2
3
4
unresolved external symbol "void __cdecl Mortgage(float &,float &,float &,bool)" (?Mortgage@@YAXAAM00_N@Z) referenced in function _main
unresolved external symbol "void __cdecl Printreport(int &,float &,bool)" (?Printreport@@YAXAAHAAM_N@Z) referenced in function _main
unresolved external symbol "void __cdecl Autoloan(float &,float &,float &,bool)" (?Autoloan@@YAXAAM00_N@Z) referenced in function _main
unresolved external symbol "void __cdecl Getinput(int &,float &,float &,float &)" (?Getinput@@YAXAAHAAM11@Z) referenced in function _main


You have linker errors. The linker cannot find definitions for Mortgage, Printreport, Autoloan, Getinput.

All these errors are because your '{', '}' and ';'s are in the wrong place.

After every function definition you have a ';', making it a prototype. And all you definitions are inside the main function.
Last edited on
I fixed the errors you listed, and I appreciate your help, but I'm not sure how to fix the Loantype2. I moved it out of the function (since it shouldn't have been in there in the first place) but it still gives me the unidentified error. Loantype2 is based upon what loantype is. Hence the "if" statement for loantype2.

Also, when I fixed the brackets and semicolons, all of the functions except one come out fine. This is the one that has an error, and I can't see what's wrong with it, either.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
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;
		}
	}
I am at a total loss on this.
Just format your code properly, then you'll see if you have any extra or missing braces.

For the record, proper formatting looks like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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;
  }
}
Last edited on
If you repost the full code in the proper format I'll take a look at it.
I can't do much with "I get a error here" without knowing the rest of the code.

I think you still have prototypes that have no definition.

Edit:
And one more thing, if you put your main function at the bottom of your code, there is no reason to use the prototypes. This may fix your problem. First try to order your code so it doesn't use prototypes, if you can't then you use prototypes. At least thats my code-convention.
Last edited on
Your prototypes don't match the definitions. If the prototype says bool Eligible then the definition should say bool Eligible. Also, you should check your old post on this subject.
Topic archived. No new replies allowed.