Expected Unqualified id
Oct 22, 2013 at 3:14am UTC
I cannot figure out why this code will not compile. Xcode displays the error "Expected unqualified-id". The errors are in the very last lines of the code starting with line 85. I'd appreciate help from anyone who can figure this out. 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 84 85 86 87 88 89 90 91
#include <iostream>
using namespace std;
int main()
{
int age, choice;
double weight, height, BMR, bars;
char gender;
cout << "Input your age." << endl;
cin >> age;
cout << "Input your weight." << endl;
cin >> weight;
cout << "Enter your height." << endl;
cin >> height;
cout << "Input your gender." << endl;
cin >> gender;
cout << "Are you sedentary, somewhat active, active, or highly active? Input 1, 2, 3, or 4." << endl;
cin >> choice;
if (choice == 1)
{
if (gender == 'M' )
{
BMR = ((655 + (4.3 * weight) + (4.7 * height) - (4.7 * age))) * 1.2;
cout << "your BMR is " << BMR << endl;
}
if (gender == 'F' )
{
BMR = ((66 + (6.3 * weight) + (12.9 * height) - (6.8 * age))) * 1.2;
cout << "your BMR is " << BMR << endl;
}
if ((gender != 'M' ) && (gender != 'F' ))
{
cout << "ERROR" << endl;
}
}
if (choice == 2)
{
if (gender == 'M' )
{
BMR = ((655 + (4.3 * weight) + (4.7 * height) - (4.7 * age))) * 1.3;
cout << "your BMR is " << BMR << endl;
}
if (gender == 'F' )
{
BMR = ((66 + (6.3 * weight) + (12.9 * height) - (6.8 * age))) * 1.3;
cout << "your BMR is " << BMR << endl;
}
if ((gender != 'M' ) && (gender != 'F' ))
{
cout << "ERROR" << endl;
}
}
if (choice == 3)
{
if (gender == 'M' )
{
BMR = ((655 + (4.3 * weight) + (4.7 * height) - (4.7 * age))) * 1.4;
cout << "your BMR is " << BMR << endl;
}
if (gender == 'F' )
{
BMR = ((66 + (6.3 * weight) + (12.9 * height) - (6.8 * age))) * 1.4;
cout << "your BMR is " << BMR << endl;
}
if ((gender != 'M' ) && (gender != 'F' ))
{
cout << "ERROR" << endl;
}
}
if (choice == 4)
{
if (gender == 'M' )
BMR = ((655 + (4.3 * weight) + (4.7 * height) - (4.7 * age))) * 1.5;
cout << "your BMR is " << BMR << endl;
}
if (gender == 'F' )
{
BMR = ((66 + (6.3 * weight) + (12.9 * height) - (6.8 * age))) * 1.5;
cout << "your BMR is " << BMR << endl;
}
if ((gender != 'M' ) && (gender != 'F' ))
{
cout << "ERROR" << endl;
}
}
if ((choice > 4) || (choice < 1))
cout << "ERROR" << endl;
bars = (BMR / 230);
cout << "The number of chocolate bars that you must eat to maintain your bodyweight is " << bars << "." << endl;
return 0;
}
Last edited on Oct 22, 2013 at 3:26am UTC
Oct 22, 2013 at 3:30am UTC
The error is not in the line 85 .It is before it coz you miss an opening brace
try to alter this piece of code
1 2 3 4
if (gender == 'M' )
BMR = ((655 + (4.3 * weight) + (4.7 * height) - (4.7 * age))) * 1.5;
cout << "your BMR is " << BMR << endl;
}
to
1 2 3 4 5
if (gender == 'M' )
{
BMR = ((655 + (4.3 * weight) + (4.7 * height) - (4.7 * age))) * 1.5;
cout << "your BMR is " << BMR << endl;
}
Hope that helps
Oct 22, 2013 at 3:38am UTC
Thanks, that helps vey much.
Topic archived. No new replies allowed.