March 22, 2018
You can have a look at the code presented during the lecture, at http://spots.augusta.edu/caubert/teaching/2018/spring/csci1301/lab/20/2018_03_22.zip, and make sure you understand it before moving on.
We will revisit our guessing game from Lab 13 – Part II. Read carefully the challenge below, and think about the parts of your previous program you can re-use to solve this one.
Write a program that asks the user which level of difficulty (s)he wants to play: easy, medium or hard. Then, generate a random number: between 0 and 10 for easy, between 0 and 50 for medium, and between 0 and 100 for hard. Then, let the user try to guess the number you randomly generated:
Two trains are on the same track at opposite ends, but traveling toward each other. Ask the user to enter the starting position and speed (in MPH) of each train. Display each train’s position every hours until they have collided. The starting time is 0 and goes up by 1’s.
You don’t have to calculate the exact collision point, just stop displaying messages after the collision.
t = (p2 − p1)/(s1 + s2)
d = p1 + (s1 × t)
where