Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Using Switch statement (http://www.go4expert.com/forums/using-switch-statement-t2275/)

 Ubha 17Dec2006 22:56

Using Switch statement

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.

 DaWei 17Dec2006 23:07

Re: Using Switch statement

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.

 Aztec 18Dec2006 05:50

Re: Using Switch statement

Quote:
 Originally Posted by Ubha 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.
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

 shabbir 18Dec2006 05:54

Re: Using Switch statement

Quote:
 Originally Posted by DaWei Be sure and read the FAQ regarding posting questions, if you haven't yet.
Link at the top right corner.

 All times are GMT +5.5. The time now is 01:12.