| KhaledSH (5) | |
|
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!! | |
|
|
|
| Aikon (75) | |
Try fixing cin>> w>>"\n";.Any doubt post again. | |
|
|
|
| KhaledSH (5) | |
| still not working D: | |
|
|
|
| Marcos Modenesi (35) | |||
|
I´m really new to programming, but this might help you: 1) if sentence should have this syntax:
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. | |||
|
|
|||
| James2250 (248) | |
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
|
|
| KhaledSH (5) | |
|
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") | |
|
|
|
| Marcos Modenesi (35) | |
|
Sorry, James 2250, I can´t find {} in KhaledSH´s code, can you help me understand that? thank you! | |
|
|
|
| James2250 (248) | |
|
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 {}. | |
|
|
|
| Marcos Modenesi (35) | |||
This works on Code::Blocks
| |||
|
|
|||
| KhaledSH (5) | |
|
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"); } | |
|
|
|
| Marcos Modenesi (35) | |
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. codenot code | |
|
|
|
| KhaledSH (5) | |
|
hahaha it Finlay worked! :D :D thx Marcos and James!! oh and thx Aikon =) | |
|
|
|
| Marcos Modenesi (35) | |
|
Great, KhaledSH!!! Good luck! | |
|
|
|