1: | Which general type of statement would you use to implement each of the following logical descriptions:
|
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):
|
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:
|
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. |