CCC '08 J1 - Body Mass Index

View as PDF

Submit solution

Points: 3
Time limit: 2.0s
Memory limit: 64M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig
Canadian Computing Competition: 2008 Stage 1, Junior #1

The Body Mass Index (BMI) is one of the calculations used by doctors to assess an adult's health. The doctor measures the patient's height (in metres) and weight (in kilograms), then calculates the BMI using the formula:

\displaystyle  BMI = \frac{weight}{height \times height}

Write a program which takes the patient's weight and height as input, calculates the BMI, and displays the corresponding message from the table below.

BMI Category Message
More than 25 Overweight
Between 18.5 and 25.0 (inclusive) Normal weight
Less than 18.5 Underweight

Sample Input 1

69
1.73

Output for Sample Input 1

Normal weight

Explanation for Output in Sample Input 1

The BMI is \frac{69}{1.73 \times 1.73} which is approximately 23.0545. According to the table, this is a "Normal weight".

Sample Input 2

84.5
1.8

Output for Sample Input 2

Overweight

Explanation for Output in Sample Input 2

The BMI is \frac{84.5}{1.8 \times 1.8}, which is approximately 26.0802. According to the table, this is "Overweight".


Comments


  • -9
    bestcreatorT  commented on Sept. 23, 2020, 4:47 a.m. edit 2

    This comment is hidden due to too much negative feedback. Click here to view it.


  • -2
    Lithium  commented on July 14, 2020, 10:54 p.m.

    for the "Normal weight" I had it check if it was not in between 18.5 and 25 instead of in-between


  • 0
    LucaC  commented on June 30, 2020, 9:16 a.m.

    How do you multiply decimals in python3? Mine always says,

    Traceback (most recent call last): File "program.py", line 2, in <module> h = int(input()) ValueError: invalid literal for int() with base 10: '1.73'

    Do you have to do some weird maths formula to work your way around this?


    • 2
      sjay05  commented on June 30, 2020, 9:21 a.m.

      Instead of reading input with int(input()) read it as a float float(input()).


      • 0
        LucaC  commented on July 3, 2020, 11:11 p.m.

        Thank you! I now know how to use decimals in python maths!


  • -3
    Henry_Z  commented on June 18, 2020, 8:34 p.m.

    I got so confused when I saw the output and when I realized it was weight first and not height, I got kinda salty.😂😂😂😂😂😂😂😂


  • -1
    Renegades  commented on March 28, 2020, 11:40 a.m.

    Mine always says IR for the execution results lol


  • -1
    ericzhou9  commented on Feb. 9, 2019, 10:46 a.m.

    me too it always say INput mismatch


  • -1
    retronerd2016  commented on Oct. 28, 2017, 8:31 p.m.

    how do you make it so that it doesn't tell you INput misMatch all the time, I try to insert a decimal in the console and it can't show up.


  • 9
    Mr_Lim  commented on Oct. 24, 2017, 12:24 p.m.

    "Write a program which prompts for the patient's height and weight" should be changed. No prompting should be done, and the input order is weight first, then height.


    • 3
      Phoenix1369  commented on Oct. 26, 2017, 4:20 p.m.

      Fixed, thanks!


  • -17
    mozart  commented on Oct. 1, 2017, 9:53 a.m.

    This comment is hidden due to too much negative feedback. Click here to view it.


    • 10
      TheCallousSword  commented on June 22, 2020, 7:09 p.m.

      Mans writing decimals like ip addresses