6.5. Exercises

  1. Suppose a movie theatre charges half price for children 12 or under or adults age 65 or older. Write an if statement that accounts for this pricing policy.

  2. What are the important style considerations when you're writing if-else statements?

  3. When is it appropriate to use a cascading if statement?

  4. What errors do you see in the following code snippet?

    if  (x = y);
    
    {
         price =* .06;
    
         }
  5. Suppose a small pizza sells for $6, a medium is a dollar more, and a large is a dollar more than a medium. Assuming that the variable size stores the customer's selection, how would you write the code to determine the final price?

Get Beginning C# 3.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.