Menu
Coddy logo textTech

Recap Challenge #2

Part of the Fundamentals section of Coddy's C journey — lesson 36 of 63.

challenge icon

Challenge

Easy

Create a program that reads a person's weight (in kg) and height (in meters), then:

  1. Validates that weight is between 30 and 300 kg
    If weight is out of range, print: Weight out of range!
  2. Validates that height is between 1.0 and 2.5 meters
    If height is out of range, print: Height out of range!
  3. If all validations pass, calculates and prints the BMI (Body Mass Index) with 1 decimal place
    • BMI formula: weight / (height * height)
  4. 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

Example output format for valid input:

BMI: 24.8
Category: Normal weight

Try 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