Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
234 CHAPTER 5 Conditions, Logical Expressions, and Selection Control Structures 16. How do you fix a nested If statement that has a dangling ? 17. How would you write a Boolean expression in an If statement if you want the state- ment's then-clause to execute when file is in the fail state? 18. Is there any limit to how deeply we can nest If statements? Programming Warm-Up Exercises 1. Write a Boolean expression that is true when the variable has the value or the value . 2. Write a Boolean expression that is true when both and are in the fail state. 3. Write a branching statement that reads into a string variable called , from a file called , if the file is not in the fail state. 4. Write a branching statement that tests whether one date comes before another. The dates are stored as integers representing the month, day, and year. The variables for the two dates are called , , , , , and . The statement should output an appropriate message depending on the outcome of the test. For example: or 5. Change the branching statement that you wrote for Exercise 4 so that when the first 6. 7. 8. 9. date doesn't come before the second, it sets the first date equal to the second date in addition to printing the message. Write a Boolean expression that is when either of the variables or is , but is whenever both of them are or neither of them is . Write a branching statement that tests whether is in the range of 0 to 100, and outputs an error message if it is not within that range. Change the branching statement that you wrote for Exercise 7 so that when is in the proper range, it adds to a running total variable called and increments a counter called . Write a code segment that reads an value from each of two files, and . If neither file is in the fail state, the program writes the lesser value of the two to a file called , and reads another value from the file that had the lesser value. If either of the files is in the fail state, then the value from the file that is not in the fail state is written to . If both files are in the fail state, then an error message is output to . The values can be input into variables and .