While Loop Messed Up

Okay, I can't figure out what I'm doing wrong with my while loop. It's the first loop posted in my code. I have the braces set up and all of the text reads like I think it should, yet nothing I try works. The else statement is the only part of the code that is giving me an error. Line 24. Any help is appreciated. Thanks.

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
#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);}
	}	

		if (Loantype = 1)
			Loantype2 = "Auto";
		else if (Loantype = 2)
			Loantype2 = "Mortgage";
	//*********************************************

	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: " << 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;}
	}}
Good God, man. You need to indent properly. It looks like you have all sorts of mismatching brace errors, but they're hard to see because your indentation is terrible.

Also, don't put semicolons after if statements or function names. Basically you follow statements with either a semicolon OR an opening brace, but you never do both.

Also main should return an int, always. It should never be a void.

Here's your main touched up. My changes (apart from the indending) are in comments:

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
int main ()  // int main
{
    int Loantype;
    float Income, Totaldebt, Loanamount;
    bool Eligible;
    string Loantype2;

//    while(Loantype != 3)  you never set Loantype to anything
//    never check a varaible before you assign it somehow.  This is probalby why your
//    while loop wasn't working.
//    instead, make this a do while
    do
    {
        Getinput(Loantype, Income, Totaldebt, Loanamount);
        if(Loantype == 1)   // no semicolon here
        {
            Autoloan (Income, Totaldebt, Loanamount, Eligible);
            Printreport (Loantype, Loanamount, Eligible);
        }
        else if(Loantype == 2)  // no semicolon here either
        {
            Mortgage(Income, Totaldebt, Loanamount, Eligible);
            Printreport (Loantype, Loanamount, Eligible);
        }
    }while(Loantype != 3);	

    if (Loantype = 1)
        Loantype2 = "Auto";
    else if (Loantype = 2)
        Loantype2 = "Mortgage";

}  // you were missing this closing brace 
while youre working if you think your indention is incorrect, if youre working in Visual Studio just hit (ctrl +a) -> (ctrl + k) -> (ctrl + f)
I typed out the code just like the instructor showed the class. When the code produced errors, I checked over it and correct as much as I could. He told us to set the loantype to not equal 3 so that the loop ends when the user enters a 3.

Thank you for your help and input. I feel like I would have flunked this class without the help of this forum. The instructor has been of no help these past 10 weeks.
sorry indentation* . By indenting correctly you'll find where you're missing braces, parentheses, etc.
Now I get no errors showing up in Visual, but the code won't build. I hate this class so much.
Are there any places online that I can go to get more in-depth tutorials or tutors? After the past few weeks of my instructor handing out code that tends to come out incorrectly, I'm having less faith in myself to complete this course properly.
Kness, Did you get this working?
In lines 30 and 32 you used the assignment operator (=) instead of the equality one (==).
Topic archived. No new replies allowed.