It keeps saying i have a statement missing after my logical expression

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
#include<iostream.h>
#include<conio.h>
#include<math.h>



int main()
{
//input
float age, weight, HeartBeatRate, CaloriesBurned, minutes;
char gender[3], name[41];


cout<<"Hello! I'm Calories Calculator from HealthDotCom. My job is to calculate your calories burned"<<endl;
cout<<"Let's get to know you"<<endl;
cout<<"Tell me your name"<<endl;
cin.getline(name,40);

cout<<"Please state your gender"<<endl;
cout<<"Female=F     Male=M"<<endl;
cin.getline(gender,2);


cout<<"Now, please enter your age (in years)"<<endl;
cin>>age;

cout<<"Great! Now, please enter your weight (in kg)"<<endl;
cin>>weight;

cout<<"How long did you took to complete this exercise? (in minutes)"<<endl;
cin>>minutes;

cout<<"What is your average heart beat rate after you did this exercise? (per minute)"<<endl;
cin>>HeartBeatRate;



if (strcmp(gender, "female")==0)
{
CaloriesBurned= ((age*0.074) - weight*0.05741) + (((HeartBeatRate*0.4472)- 20.4022)*minutes/4.184);

cout<<"Age= "<<age<<endl;
cout<<"Weight= "<<weight<<endl;
cout<<"Heart Beat Rate (per minute)= "<<HeartBeatRate<<endl;
cout<<"Duration of exercise= "<<minutes<<endl;

cout<<"You have burned "<<CaloriesBurned<<"calories"<<endl;
}


else (gender, "male")==0) // this is where it says that i have a statement missing
{

CaloriesBurned= ((age*0.2017)- weight*0.09036)+(((HeartBeatRate*0.6309)- 55.0969)*minutes/4.184);

cout<<"Age= "<<age<<endl;
cout<<"Weight= "<<weight<<endl;
cout<<"Heart Beat Rate (per minute)= "<<HeartBeatRate<<endl;
cout<<"Duration of exercise (in minutes)= "<<minutes<<endl;

cout<<"The total calories burned for you is "<<CaloriesBurned<<endl;
}

cout<<"Congratulations, "<<name<<"! That is a great job!"<<endl;
cout<<"Keep it up!";

getch();
return 0;

}


and when i run the program after putting the semicolon there, the answer is wrong (logic error)

help me please
Last edited on
Hi,

Please use code tags

http://www.cplusplus.com/articles/jEywvCM9/

also don't you think you are missing strcmp statement on the line you mention has error?

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
if (gender == 'f' || 'F')
{
CaloriesBurned= ((age*0.074) - weight*0.05741) + (((HeartBeatRate*0.4472)- 20.4022)*minutes/4.184);

cout<<"Age= "<<age<<endl;
cout<<"Weight= "<<weight<<endl;
cout<<"Heart Beat Rate (per minute)= "<<HeartBeatRate<<endl;
cout<<"Duration of exercise= "<<minutes<<" mins"<<endl;

cout<<"You have burned "<<CaloriesBurned<<" calories"<<endl;
}


else (gender == 'm' || 'M')
{

CaloriesBurned= ((age*0.2017)- weight*0.09036)+(((HeartBeatRate*0.6309)- 55.0969)*minutes/4.184);

cout<<"Age= "<<age<<endl;
cout<<"Weight= "<<weight<<endl;
cout<<"Heart Beat Rate (per minute)= "<<HeartBeatRate<<endl;
cout<<"Duration of exercise (in minutes)= "<<minutes<<" mins"<<endl;

cout<<"You have burned "<<CaloriesBurned<<" mins"<<endl;
}

cout<<"Congratulations, "<<name<<"! That is a great job!"<<endl;
cout<<"Keep it up!";

getch();
return 0;

}


i've change my logical expression and it still says that i have my statement missing
Last edited on
include string header file and try again
You really really need to learn to use some kind of indentation style. IMO your program is almost impossible to read without the indentation and the total lack of whitespace in your statements.
https://en.wikipedia.org/wiki/Indent_style

You have several problems with your if/else statements.

First look at this snippet:
if (gender == 'f' || 'F')
This is not how you use the logical operators in C++. You must have complete comparisons on both sides of the operator.
if (gender == 'f' || gender == 'F')
You could alternatively just use toupper() or tolower() instead.
if (tolower(gender) == 'f')

Next, look at this snippet:
else (gender == 'm' || 'M')
The else statement stands on it's own, no comparisons are allowed.

Perhaps you should review your documentation on if/else statements.
http://www.cplusplus.com/doc/tutorial/control/

thank you everyone! i did it all over again. and its working.
Also, just as advice don't use <iostream.h>, use <iostream>.

iostream.h is outdated.
Topic archived. No new replies allowed.