# Review Questions

 1: Which general type of statement would you use to implement each of the following logical descriptions: If number is greater than 100, write "greater than 100" onscreen; otherwise, write "less than or equal to 100." Repeatedly check each letter of a string until no more letters are left in the string. 2: Suppose that your program contains three variables called rainfall, wind, and temperature, all of type double. For each of the following points, write a few lines of code that implement the described logic (you don't need to write the whole program): If rainfall is greater than 100, write "Heavy rainfall" onscreen. If rainfall is greater than 100 or wind is greater than 120, write "Bad weather" onscreen. If rainfall is equal to 0 and wind is less than 10 and temperature is between 23 and 27 (Celsius), write "Nice weather." If rainfall is equal to 0, write "It is not raining"; otherwise, write "It is raining." 3: No matter which value rainfall has, the following lines will always write "It's raining" onscreen. Why? ` if(rainfall > 10); Console.WriteLine("It's raining"); ` 4: What is the purpose of nested if statements? 5: Write logical expressions (using C#'s comparison operators and logical operators) that represent the following conditions: rainfall is between 100 and 150. number is odd and not equal to 23. number is even and smaller than 100, or weight is less than 100. 6: A method with the header bool IsEven(int number) returns true if the argument passed to its parameter number is even; otherwise, it returns false. Write a Boolean expression containing a call to IsEven that is true if the number passed along with the call is odd. 7: To what does the term scope refer? 8: What is one of the few correct uses of the goto statement? 9: Rewrite the following if-else multibranch statement using a switch statement. ` if(timeOfDay == "morning") Console.WriteLine("Good Morning"); else if(timeOfDay == "midday") Console.WriteLine("Good Day"); else if(timeOfDay == "evening") Console.WriteLine("Good evening"); else Console.WriteLine("Invalid time"); ` 10: To what does "falling through" in relation to the switch statement refer? How can "falling through" be prevented? 11: Your program contains variables called cost1, cost2, and minimumCost. Write a statement involving the conditional operator that assigns the smaller of the values in cost1 and cost2 to minimumCost.

C Primer Plus (5th Edition)
ISBN: 0672326965
EAN: 2147483647
Year: 2000
Pages: 286
Authors: Stephen Prata

Similar book on Amazon