Need help ASAP. Project due at midnight.



//Ja-Mesz Walton
//3/6/16
//Midterm project regarding calculating Body Mass Index
// CIS1111

#include <iostream>
#include <iomanip>
#include <string>
#include <cstdlib>
using namespace std;

int main()
{
//named constants
const double BMI_MIN = 18.5;
const double BMI_MAX = 25;

//Delcared variables
string userName;
double bmi;
int gendertype;
double weight;
int height;
double calories;


cout << "This program calculates Body Mass Index and daily calorie recommendations." << endl;

//input information
cout << "Enter your name:";
getline(cin, userName);

cout << "Enter your weight in pounds:";
cin >> weight;

cout << "Enter your height in inches:";
cin >> height;

cout << "Select your gender and activity level from this list." << endl;
cout << "1. Moderately Active Female" << endl;
cout << "2. Moderately Inactive Female" << endl;
cout << "3. Moderately Active Man" << endl;
cout << "4. Moderately Inactive Man" << endl;
// Enter Gender type
cout << " Enter your selection: ";
cin >> gendertype;

if (gendertype == 1)
{
//Active female
calories = weight * 12;
if (weight < BMI_MIN) //Active Female is underweight
{
std::cout << "Weight Category: Underweight" << endl;
}
else if (weight > BMI_MAX) //Active Female is overweight
{
std::cout << "Weight Category: Overweight" << endl;
}
else // Active Female is optimum weight
{
std::cout << "Weight Category: Optimum" << endl;
}


{
if (gendertype == 2)
{
if (weight < BMI_MIN) // Inactive female is underweight
{
std::cout << "Weight Category: Underweight" << endl;
}
else if (weight > BMI_MAX) // Inactive Female is overweight
{
std::cout << "Weight Category: Overweight" << endl;
}
else // Inactive Female is optimum weight
{
std::cout << "Weight Category: Optimum" << endl;
}

{
if (gendertype == 3)
{
if(weight < BMI_MIN) //Active Male is underweight
{
std::cout << "Weight Category: Underweight" << endl;
}
else if (weight > BMI_MAX) //Active Male is overweight
{
std::cout << "Weight Category: Overweight" << endl;
}
else // Active Male is optimum weight
std::cout << "Weight Category: Optimum" << endl;
}
{
if (gendertype == 4)
{
if (weight < BMI_MIN) // Inactive Male is underweight
{
std::cout << "Weight Category: Underweight" << endl;
}
else if (weight > BMI_MAX) // Inactive Male is overweight
{
std::cout << "Weight Category: Overweight" << endl;
}
else // Inactive Male is optimum weight

std::cout << "Weight Category: Optimum" << endl;
{

}


// Body Mass Index (BDM) formula
bmi = weight * 703 / (height * height);

if (bmi < BMI_MIN)
{
//Underweight
std::cout << "Weight Category: Underweight" << endl;
}
else if (bmi > BMI_MAX)
{
//Overweight
std::cout << "Weight Category: Overweight" << endl;
}
else
{
//Optimal weight
std::cout << "Weight Category: Optimum" << endl;
}

return 0;
}

Error 1 error C1075: end of file found before the left brace '{' at 'c:\users\hp pc\documents\ja-mesz work\midterm project draft\midterm project draft\midterm project source draft.cpp(96)' was matched c:\users\hp pc\documents\ja-mesz work\midterm project draft\midterm project draft\midterm project source draft.cpp 136 1 Midterm project draft

2 IntelliSense: expected a '}' c:\Users\HP PC\Documents\Ja-Mesz Work\Midterm project draft\Midterm project draft\Midterm project source draft.cpp 135 1 Midterm project draft

Last edited on
You've got unmatched opening and closing braces { and }.

According to my editor, main() ends somewhere about line 91:
80
81
82
83
84
85
86
87
88
89
90
91
		else if (gendertype == 3)
		{
		if (weight < BMI_MIN) //Active Male is underweight
			cout << "Weight Category: Underweight" << endl;
		}
		else if (weight > BMI_MAX) //Active Male is overweight
		{
			cout << "Weight Category: Overweight" << endl;
		}
		else // Active Male is optimum weight	
			cout << "Weight Category: Optimum" << endl;
		} //--------------------------- end of main ------------------------ 

Crap. So what do I do?
Indent your code properly. When you don't use code tags, the forum eats all the leading spaces, so I can't tell how you've indented your code. Proper indentation makes unmatched open/close brace errors obvious.
Instead of
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int main()
{
int a = 5;
for(int i = 0; i < a; i++)
{
if(i % 2 == 0)
{
std::cout << i << " is even" << std::endl;
}
else
{
std::cout << i << " is odd" << std::endl;
}
}
}
say
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int main()
{
    int a = 5;
    for(int i = 0; i < a; i++)
    {
        if(i % 2 == 0)
        {
            std::cout << i << " is even" << std::endl;
        }
        else
        {
            std::cout << i << " is odd" << std::endl;
        }
    }
}
Things are easier if you have an editor which highlights it for you. But doing it by hand, start by looking at this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
	if (gendertype == 1)
	{
		//Active female
		calories = weight * 12;
		if (weight < BMI_MIN) //Active Female is underweight
		{
			cout << "Weight Category: Underweight" << endl;
		}
		else if (weight > BMI_MAX) //Active Female is overweight
		{
			cout << "Weight Category: Overweight" << endl;
		}
		else // Active Female is optimum weight
		{
			cout << "Weight Category: Optimum" << endl;
		}
	}

Above - everything is nicely matched up. Now look at the code further down:
1
2
3
4
5
6
7
8
9
10
11
12
13
	else if (gendertype == 3)
	{
		if (weight < BMI_MIN) //Active Male is underweight
			cout << "Weight Category: Underweight" << endl;
		}
		else if (weight > BMI_MAX) //Active Male is overweight
		{
			cout << "Weight Category: Overweight" << endl;
		}
		else // Active Male is optimum weight	
			cout << "Weight Category: Optimum" << endl;
		}
	}


there, the open brace at line 2 matches the closing brace at line 5 - though it surely should not do - there is an open brace missing. There are a number of mismatches like that. You need to carefully go through and make sure they are in nice matched pairs.
There, the code should I think look more like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
	else if (gendertype == 3)
	{
		if (weight < BMI_MIN) //Active Male is underweight
		{
			cout << "Weight Category: Underweight" << endl;
		}
		else if (weight > BMI_MAX) //Active Male is overweight
		{
			cout << "Weight Category: Overweight" << endl;
		}
		else // Active Male is optimum weight	
		{
			cout << "Weight Category: Optimum" << endl;
		}
	}
Last edited on
Ok. I fixed it more thanks to you guys, but my last two errors are these.
Error 1 error C1075: end of file found before the left brace '{' at 'c:\users\hp pc\documents\ja-mesz work\midterm project draft\midterm project draft\midterm project source draft.cpp(68)' was matched c:\users\hp pc\documents\ja-mesz work\midterm project draft\midterm project draft\midterm project source draft.cpp 134 1 Midterm project draft

2 IntelliSense: expected a '}' c:\Users\HP PC\Documents\Ja-Mesz Work\Midterm project draft\Midterm project draft\Midterm project source draft.cpp 133 1 Midterm project draft
There's a related but different error here:
1
2
3
else if (gendertype == 4)
{
if (weight < BMI_MIN // Inactive Male is underweight 


there is a missing ) after BMI_MIN in the if condition.
Topic archived. No new replies allowed.