Part 3 of C++ Workshop
PROGRAM: How Old am I?
Make a program which displays a different message depending on the age given. Here are the possible responses:
- age is less than 16, say "You can't drive."
- age is less than 18, say "You can't vote."
- age is less than 25, say "You can't rent a car."
- age is 25 or over, say "You can do anything that's legal."
Notice that a person who is under 16 will get three messages, one for being under 16, one for also being under 18, and one for also being under 25.
Source: Graham Mitchell, programmingbydoing.com
PROGRAM: How’m I doin’?
Write a C++ program that asks the user for his/her exam score and translates it to either “Pass” or “Fail”. The output from the program might look something like this:
Hello! What’s your name? Dave
Well, hello there, Dave! If you tell me your score I’ll let you know how you did on the exam.
What was your score? (Remember it should be a number between 1 and 100) 75
Nicely done, Dave! You passed the test!
Hello! What’s your name? Linda
Well, hello there, Linda! If you tell me your score I’ll let you know how you did on the exam.
What was your score? (Remember it should be a number between 1 and 100) 56
Sadly, Linda, you failed the test. Hope you do better next time!
PROGRAM. Crazy for you.
Objective. To learn about counting and selection (if)
What to do. Write a program that asks the user a few questions and uses the answers to determine whether the user is “normal” (this probably means boring) or “crazy” (this probably means awesome). For example:
Hello! We will be playing a game to determine if you are normal!
<Demented laughter> Let's get to it.
What is your first name? Linda
Linda, the rules of the game are as follows:
I will ask you a series of questions and you will answer with
either a 'y' for yes or 'n' for no.
MAKE SURE TO MAKE NO TYPOS. Got it? Good.
Ready to play? y
Do you like Mexican food? y
Do you think Harry Potter is amazing? y
Are you addicted to your phone? y
Do you like the song "Hello" by Adele? n
Do you like the game "Pokemon Go"? y
CONGRATULATIONS, Linda!! You may now rejoin society secure in the knowledge that you are indeed crazy enough to be a programmer!