Skip to content

Are you free yet?

  • Project
  • 2 hints
  • 3 of 7 in this chapter

Are you truly free yet?

To a lot of teenagers and young adults, freedom is first felt when they have the opportunity to leave their homes on their own and drive off to wherever they want to go. This is the ‘freedom’ one feels when he or she first drives.

Challenge

For this project, you will write a program that checks to see if you are legally allowed to drive a car yet.

There are 2 prerequisites that must be met:

  • You must be 15 (in Texas)
  • You must have finished a drivers’ ed course.

We will check both in this program. The input variables (which you must define at the beginning of the program) are age (an integer) and completed_course (a boolean).

Use those two variables, and print a message saying whether the teenager or young adult can drive or not.

Hints

Hint 1What is a boolean?

Remember, booleans are variables that are either true or false. You either completed the course or didn't..

Hint 2What is an int?

An int, or integer, as a whole number with no floating/fractional component. For example, 17 is an integer, but 17.5 is not.

Solution

Swift
var age = 17 // Give any value you like and test your program.
var completed_course = false // Give any value to this as well! You can keep testing with different values
if age >= 15 && completed_course {
 print("You are ready to be free! Congratulations!")
}
if age < 15 {
 print("You are not old enough to hop into the driver's seat yet. Wait a few years and you'll be ready!!!")
}
if !completed_course {
 print("You should probably get that drivers' ed course done if you want to drive ;). It's important, and will take some effort, but with determination, you can get through and you'll be ready for 'freedom'")
} 

Give the project a try first.