1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Using Switch statement

Discussion in 'C' started by Ubha, Dec 17, 2006.

  1. Ubha

    Ubha New Member

    Joined:
    Dec 17, 2006
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Dear all,

    I have one question.

    Enter a persons weight in kilograms and height in metres. Calculate the persons Quetelet Index (kolos/(meters *meters)). Print out the Quetelet Index and an appropriate message as indicated by the table below.
    Below 20 Underweight
    20 to below 35 Healthy weight
    25 to below 30 Midly overweight
    30 to below 40 Very overweight
    40 and above Extermely overweight

    I did this using If else statement but now i want to do this with switch statement.I tried but not successfull. Please help and guide.
     
  2. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    Put up your code for us to look at. Very few of us read minds.

    Bear in mind that the case values are constants, not variables. Use a break at the end of each case unless you want execution to fall through to the next statement.

    Be sure and read the FAQ regarding posting questions, if you haven't yet.
     
  3. Aztec

    Aztec New Member

    Joined:
    May 9, 2006
    Messages:
    90
    Likes Received:
    0
    Trophy Points:
    0
    Well, keep yourself in our position and try to answer the question.
    Atmost I can direct you to a tutorial which can teach you the usage of switch case
    http://www.cprogramming.com/tutorial/lesson5.html
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    Link at the top right corner.
     

Share This Page