Homework 5: Conditionals

Wednesday, February 29, 2012     


[Up] [Previous Homework] [Next Homework]


Example Solution

Complete the following:

  1. Create a new file called hw05.c
  2. For this homework you will be getting character input (y or n for yes or no questions) see for how to get a single character for input
  3. NEW NOTE A second example to show how to read an integer and then a single character (y or n for yes or no questions)
  4. You are going to create a program that will ask the user a series of questions.
  5. Some questions will require additional details that you will prompt the user for and then respond to.
  6. At the end of the series of questions, you will inform the user if they are allowed to drive or not.
  7. Ask the questions in the following order, and at any point, if the user cannot drive, end the questioning. In other words, if the user says they haven't had a learner's permit, stop the questions and say they cannot drive.
  8. You need to ask the following questions:
    • How old are you? (verify they are 18 or older)
    • Have you had a learners permit y/n?
    • How long have you have a learner's permit? (verify it is over 6 months)
    • Have you had your license suspended y/n?
    • Have you been drinking alcohol tonight y/n?
    • If they've been drinking, ask the following additional questions:
      • Are you under 21 y/n?
      • Are you driving a commercial vehicle y/n?
      • What is your BAC (blood alcohol content)?
      • Verify that the user's BAC is less than .02 if they are under 21, less than .08 if they are 21 or older, and less than .04 if they are driving a commercial vehicle
    • Are the roads treacherous y/n?
  9. At the end of the questions print either "You can drive" or "You cannot drive"
  10. Create a script of you running your program three times, the first two times fail at different points, and the third time get the output saying you can drive.
  11. Once you are done, use submit to submit two files, hw05.c and typescript

    linux3[1]% submit cs104_sheets hw05 hw05.c typescript