Recap Challenge #2
Part of the Fundamentals section of Coddy's C journey — lesson 36 of 63.
Challenge
EasyCreate a program that reads a person's weight (in kg) and height (in meters), then:
- Validates that weight is between 30 and 300 kg
If weight is out of range, print:Weight out of range! - Validates that height is between 1.0 and 2.5 meters
If height is out of range, print:Height out of range! - If all validations pass, calculates and prints the BMI (Body Mass Index) with 1 decimal place
- BMI formula: weight / (height * height)
- Prints the person's weight category based on BMI:
- Below 18.5:
Underweight - 18.5 to 24.9:
Normal weight - 25.0 to 29.9:
Overweight - 30.0 or higher:
Obese
- Below 18.5:
Example output format for valid input:
BMI: 24.8
Category: Normal weightTry it yourself
#include <stdio.h>
int main() {
float weight, height, bmi;
int weight_result, height_result;
weight_result = scanf("%f", &weight);
height_result = scanf("%f", &height);
// Validate input
// Calculate BMI
// Determine weight category
// Print results
return 0;
}All lessons in Fundamentals
3Operators
Arithmetic OperatorsModulo OperatorIncrement/DecrementAssignment OperatorsRelational OperatorsLogical Operators Part 1Logical Operators Part 2Logical Operators Part 3Recap Challenge