Nested if statements: Form: if (condition1) statement1; else if (condition2) statement2; ... else if (conditionN) statementN; else statementF; Each condition is tested in sequence until one evaluates to true. The statement following the first true condition executes - and the rest of the if statement is skipped. A nested if statement if (age >= 65) printf("Check your social security benefits\n"); else if (age >= 18 && age <= 21) if (gender == 'M' || gender == 'm') printf("Register for selective service\n"); else printf("Draft is optional for females\n"); else if (age = 5 || age == 6) printf("You must sign up for school\n"); Another version of the if statement. Does it provide the same behavior? if (age == 5 || age == 6) printf("You must register for school\n"); else if (age >= 18 && age <= 21) if (gender == 'M' || gender == 'm') printf("Register for selective service\n"); else printf("Draft is optional for females\n"); else if (age >= 65) printf("Check your social security benefits\n"); Switch statement switch(selector) { case label1: statements1; break; case label2: statements2; break; ... default: StatementsD; } The selector (a type int expression or a character expression) is compared to each case label. The statements following the first label with a matching value are executed until a break statement is reached. The break causes the rest of the switch statement to be skipped. switch (wattage) { case 60: printf("Good general purpose bulb\n"); price = 0.60; break; case 75: printf("Out of stock - substitute a 60 watt bulb\n"); price = 0.60; break; case 100: case 125: printf("Good bulb for a reading lamp\n"); price = 0.80; break; case 150: printf("Out of stock - substitute a 125 watt bulb\n"); price = 0.80; break; default: if (wattage > 150) printf("No bulb in stock - largest is 150 watts\n"); else printf("Standard bulbs are 60, 75, 100, 125, 150\n"); } /* assume gender (type char) has a value */ switch(gender) { case 'M': case 'm': if (age >= 65) printf("Register for social security\n"); else if (age >= 18) printf("Register for selective service\n"); else if (age >= 6) printf("Register for school\n"); break; case 'F': case 'f': if (age >= 65) printf("Register for social security\n"); else if (age >= 18) printf("Register for school\n"); break; default: printf("Invalid gender character %c\n", gender); } /* assume change and coin_value are type int and have been assigned values. */ /* For a given amount of change, determine how many coins of a particular coin value to give out - for example, if change is 35 and coin_value is 10, give out 3 dimes, if change is 35 and coin_value is 5, give out 7 nickels */ switch (coin_value) { case 1 : printf("Dispense %d pennies\n", change); break; case 5: printf("Dispense %d nickels\n", change / 5); printf("Amount left over is %d cents\n", change % 5); break; case 10: printf("Dispense %d dimes\n", change / 10); printf("Amount left over is %d cents\n", change % 10); break; case 25: printf("Dispense %d quarters\n", change / 25); printf("Amount left over is %d cents\n", change % 25); break; default: printf("No coin with value %d cents\n", coin_value); } temperature conversion program. The user can enter a temperature in either celsius or fahrenheit. The program displays both centigrade and fahrenheit temperatures. Analysis input double in_temp - the temperature in either celsius or fahrenheit output double out_temp - the equivalent temperature in the other temperature scale other program variable char temp_type: an indicator of type of temperature (C for Celsius, F for fahrenheit) formulas degrees F = 1.8 * degrees C + 32.0 degrees C = (5/9) (degrees F - 32) Design Algorithm 1. read the temperature and the units of measurement 2. Convert the temperature 3. Display the results Refine step 2. if temperature is fahrenheit convert to celsius else if temperature is celsius convert to fahrenheit #include double convert_to_fahrenheit(double); double convert_to_celsius(double); double convert_temp(char, double); void display(char, double, double); int main() { double in_temp, /* the input temperature */ out_temp; /* the equivalent temp */ char temp_type; /* the temperature scale */ /* Read the temperature and the scale */ printf("Enter a temperature:"); scanf("%lf", &in_temp); printf("Enter temperature type - C or F:"); scanf(" %c", &temp_type); /* convert the temperature */ out_temp = convert_temp(temp_type, in_temp); /* display the results */ display(temp_type, in_temp, out_temp); } double convert_temp(char temp_type, double in_temp) { double out_temp; switch (temp_type) { case 'C': case 'c': out_temp = convert_to_fahrenheit(in_temp); break; case 'F': case 'f': out_temp = convert_to_celsius(in_temp); break; default: out_temp = in_temp; } return out_temp; } double convert_to_fahrenheit(double degreesC) { return degreesC * 1.8 + 32.0; } double convert_to_celsius(double degreesF) { return 5.0 / 9.0 * (degreesF - 32.0); } joda.cis.temple.edu> cc temp_convert.c joda.cis.temple.edu> a.out Enter a temperature:100 Enter temperature type - C or F:C The temperature is 100.000000 degrees Celsius and 212.000000 degrees Fahrenheit joda.cis.temple.edu> a.out Enter a temperature:0 Enter temperature type - C or F:C The temperature is 0.000000 degrees Celsius and 32.000000 degrees Fahrenheit joda.cis.temple.edu> a.out Enter a temperature:100 Enter temperature type - C or F:f The temperature is 37.777778 degrees Celsius and 100.000000 degrees Fahrenheit joda.cis.temple.edu> a.out Enter a temperature:212 Enter temperature type - C or F:f The temperature is 100.000000 degrees Celsius and 212.000000 degrees Fahrenheit