HELP ME PLEASE!!

hey guys, can someone please help me with this code!!?


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

float BMI (float w,float h)
{
float z=(w*703/h*h);
return z;
}

void main ()
{
float w;
float h;
cout<< "please enter your wiehgt \n";
cin>> w>>"\n";

cout<< "please enter your height \n";
cin>> h>>"\n";

cout<< "your BMI is: \n";
cout<< BMI (w,h)<<"and ur health status is: \n";
if (BMI<= 20) (error here on the operator "<=")
cout<< "you are underweight \n";
else if (BMI<=25) (error here on the operator "<=")
cout << "you are normal \n";
else if (BMI <= 31) (error here on the operator "<=")
cout << "you are overweight \n":
else if (BMI <= 100) (error here on the operator "<=")
cout << " obese \n";
else
cout<< "ERROR";

system ("pause");
}

The errors im getting on the operators are (operand types are incompatible)

I dont know why my code is wrong =(
plz help!!
Try fixing cin>> w>>"\n";.

Any doubt post again.
still not working D:
I´m really new to programming, but this might help you:

1) if sentence should have this syntax:
1
2
if (BMI<= 20) {
cout<< "you are underweight \n";} 


if (condition) { what progrma shoul do if condition is true; }

You forgot to include {}

2) Don´t underestimate reading the forum suggestions regarding how to post. They will help you get more attention and dedicate answers.
cin>> w>>"\n";

That is one of the problems as mentioned above, you can't use >> to include a new line. You could put cout with \n after it to put a newline if you wanted to.

BMI is a function, to call it you need to include the () and the variables you are passing into it. For example

if (BMI(w,h)<= 20)

Otherwise you can set a variable equal to that function and just test that everytime in your if statements.
Last edited on
thx guys for the replies, but im still getting the same operators errors
it says exactly the following on each <=:
Error:operand types are incompatible ("float(*)(float w,float h)"and"int")
Sorry, James 2250, I can´t find {} in KhaledSH´s code, can you help me understand that?
thank you!
KhaledSH post your code again with updates and I will see (it works correctly for me after I change a : to ; in your code).

Marcos I thought he did include {} in his code at first but I was wrong (which is why I edited out my post). But if you only have a single statement after if statements/loops they will work correctly without the {}.
This works on Code::Blocks

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
#include <iostream>

using namespace std;

float BMI (float w,float h)
{
float z=(w*703/h*h);
return z;
}

int main ()
{
float w;
float h;
cout << "please enter your wiehgt \n";
cin >> w;

cout<< "please enter your height \n";
cin >> h;

cout<< "your BMI is: \n";
cout<< BMI (w,h) << "and ur health status is: \n";

if (BMI (w,h)<= 20) {
cout<< "you are underweight \n";}
else if (BMI (w,h)<=25) {
cout << "you are normal \n";}
else if (BMI (w,h) <= 31){
cout << "you are overweight \n";}
else if (BMI (w,h) <= 100){
cout << " obese \n";}
else {
cout<< "ERROR";}

return 0;
}
here is my final "not working code"

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

float BMI (float w,float h)
{
float z=(w*703/h*h);
return z;
}

void main ()
{
float w;
float h;
cout<< "please enter your wiehgt \n";
cin>>w;

cout<< "please enter your height \n";
cin>> h;

cout<< "your BMI is: \n";
cout<< BMI (w,h)<<"and ur health status is: \n";
if (BMI<=20)
{
cout<< "you are underweight \n";
}
else if (BMI<=25)
{
cout << "you are normal \n";
}
else if (BMI <= 31)
{
cout << "you are overweight \n";
}
else if (BMI <= 100)
{
cout << " FAT!!!! \n";
}
else
{
cout<< "EROR";
}

system ("pause");
}
As James2250 said above, for you to use your BMI funtion, you have to write this:
if (BMI(w,h)<= 20)

you call the function and include between parentheses whatever values you want to pass.

You can use the button <> at the right of the window where you type this replies to make text look like code.

code

not code
hahaha it Finlay worked! :D :D
thx Marcos and James!!
oh and thx Aikon =)
Great, KhaledSH!!!
Good luck!
Topic archived. No new replies allowed.