Range checks using a switch statement

后端 未结 7 1292
陌清茗
陌清茗 2020-12-23 02:15

My teacher has assigned a program to use both if-else statements and switch statements, so we understand how to implement both. The program asked u

7条回答
  •  清酒与你
    2020-12-23 02:52

    A switch in C++ only allows you to check for the values of integers and chars.

    The BMI is a double type, so it's not possible to check its value in a switch.

    In your solution with the switch you also should declare the variable BMI as double. If you declare it as integer all decimal results will be casted to an integer, and you will lose the decimal places.

提交回复
热议问题