+ 2

Need Help

So I am trying to print the height and weight within the main() function and also my floating number isn't coming out to decimal values; here is my code.. #include <stdio.h> int getHeight() { int height; printf("enter the height:"); scanf("%d", &height); return height; } //getHeight() double getWeight() { double weight; printf("enter the weight:"); scanf("%f", &weight); return weight; } float calculateBMI(int height, double weight) { float bmi = ((weight) / (height * height * height)); printf("Your BMI value is %d. \n", bmi); } void printBMI(float bmi) { if (bmi < 18.5) { printf("You are Underweight.\n"); } if (bmi >= 18.5 && bmi <= 24.9) { printf("You are Normal.\n"); } if (bmi >= 25 && bmi <= 29.9) { printf("You are Overweight.\n"); } if (bmi >= 30) { printf("You are Obese.\n"); } return 0; } int main() { int height; height = getHeight(); printf("height is", height); double weight; weight = getWeight(); float bmi = 0; bmi = calculateBMI(height, weight); printBMI(bmi); }

2nd Jul 2018, 4:27 PM
RaVon
RaVon - avatar
4 Antworten
+ 1
may I show you what I have now; its not calculating the bmi and returning it; it says "Your BMI value is 0"
2nd Jul 2018, 7:34 PM
RaVon
RaVon - avatar
+ 9
EmmmKut I have coded and rectified your errors.And have added full detailed commemts and errors and modification sub heading pointing out all your errors. Please check the code for further details to your problem.Hope it clarifies your doubt!! Link given below:- [edit:- I have named your program like " C bmi "which means see bmi or C program of bmi so C bmi.You can take it in anyway you want both points to same program logic ]. https://code.sololearn.com/c5y8B3fq835D/?ref=app
2nd Jul 2018, 10:42 PM
D-Key
D-Key - avatar
+ 1
Error inside int main() if you want to print the value of height variable, type like this----> printed("height is %f",height); also, inside the getWeight() & getHeight() function, change the return type and the variable type to float , so that no truncation occurs. your functions should be like this float getWeight() { float weight; // rest code here return weight; }
2nd Jul 2018, 4:46 PM
Vaibhav Sankhla
Vaibhav Sankhla - avatar
0
#include <stdio.h> int getHeight() { int height; printf("enter the height:"); scanf("%d", &height); return height; } //getHeight() double getWeight() { double weight; printf("enter the weight:"); scanf("%f", &weight); return weight; } float calculateBMI(int height, double weight) { /float bmi = ((weight) / (height * height)); printf("Your BMI value is %f. \n", bmi); return bmi; } void printBMI(float bmi) { if (bmi < 18.5) { printf("You are Underweight.\n"); } if (bmi >= 18.5 && bmi <= 24.9) { printf("You are Normal.\n"); } if (bmi >= 25 && bmi <= 29.9) { printf("You are Overweight.\n"); } if (bmi >= 30) { printf("You are Obese.\n"); } return 0; } int main() { int height; height = getHeight(); printf("height is %d\n", height); double weight; weight = getWeight(); printf("weight is %d\n", weight); float bmi = 0; bmi = calculateBMI(height, weight); printBMI(bmi); } !!should I convert ft to inches!!
2nd Jul 2018, 9:26 PM
RaVon
RaVon - avatar