The if-else Control Statement in C ---------------------------------- The "if-else" statement in C is similar to the "if-then-else" statement in C shell programming. The simplest form of the command is: if (expression) statement; Example usage: if (apples == oranges) bananas = 10; The general form of the command is: if (expression) statement1; else statement2; Example usage: if (a > 10) printf("it is large\n"); else printf("it is small\n"); A more complex form of the command is: if (expression1) statement1; else if (expression2) statement2; else if (expression3) statement3; : : else if (expression_n) statement_n; else statement_n+1; Example usage: if (a > 10) printf("it is large\n"); else if (a > 5) printf("it is medium\n"); else printf("it is small\n"); Note: No "endif" statement is needed. An even more complex form of the command would be: if (expression1) { statement1_1; statement1_2; : statement1_m; } else if (expression2) { : } else if (expression3) : : else if (expression_n) { statementn_1; statementn_2; : statementn_m; } else { statement_n+1_1; statement_n+1_2; : statement_n+1_m; } Example usage: if (number == 5) { a = 10; b = 11; } else if (number > 5) { a = 12; b = 11; printf("Hi there!\n"); } else cop = copper + pigroast + fuzz; Exercises 4.2 -- Problem #2 --------------------------- (Modified to use command line args) a) if money is in the bank for more than 5 years, then the interest rate is 9.5 percent, else the rate is 5.4 percent. Use command line args to input the number of years into the variable "num_yrs" and output the appropriate interest rate. #include #include main(int argc, char **argv) { float num_yrs = atof(argv[1]); if (num_yrs > 5.0) printf("The interest rate is 9.5 percent.\n"); else printf("The interest rate is 5.4 percent.\n"); } Sample output is: % prog_4.2 1.0 The interest rate is 5.4 percent. % prog_4.2 5.1 The interest rate is 9.5 percent. % prog_4.2 5 The interest rate is 5.4 percent. b) How many runs should you do to verify that part a) is working properly? 2 What data should you use to test each? Test one value greater than 5 and one less than or equal to 5.