Consider this broken calculator program. It attempts to implement division. It asks the user to input dividend and divisor and prints the quotient. Unfortunately, it is "broken" because it never provides the frational part. For example the result of dividing 5 by 4 is 1. Fix the program by using static_cast. You are not allowed to change the types of any of the variables used in the program. Create a project titled Lab4_Calculator with a single file titled calculator.cpp. Put the fixed calculator program there.
The computer selects a random age for the dragon. In the beginning of the game, the dragon can be between 1 and 100 years old. The user of the game plays the maiden. Note that the dragon gets older every five years. The dialog should look as follows (user input is shown in bold):
Year 1000: Hello, fair maiden. I am a fearsome dragon. How old am I? 50 Wrong, I am older. No handsome prince for you. See you in five years. Year 1005: Hello, fair maiden. I am a fearsome dragon. How old am I? 75 Wrong, I am younger. No handsome prince for you. See you in five years. Year 1010: Hello, fair maiden. I am a fearsome dragon. How old am I? 60 Wrong, I am older. No handsome prince for you. See you in five years. Year 1015: Hello, fair maiden. I am a fearsome dragon. How old am I? 63 You got it! Here is the handsome prince. Live happily ever after!For your program, you need to use predefined randomization functions rand() and srand() as well as the time function time()
rand() takes no arguments. Every time rand() is invoked it returns an integer value between 0 and constant RAND_MAX defined in cstdlib. Note that the sequence of values returned by repeated calls of rand() is uniquely determined by the seed passed to srand(). That is, if srand() is passed the same seed, rand() is going to return the same sequence of numbers. This is helpful for debugging. Check this program for an example of random number manipulation.
First, debug the code when the dragon does not age between the guessing attempts.
Use fixed values of the seed for your initial debugging, use the output of time() as an unpredictable seed to start the guessing game once you debugged your program.
Do not put srand() inside the loop or anywhere, where it may be invoked more than once - it resets the random number generator.
Milestone: implement the dragon printing his age.
Make sure your program adheres to proper programming style. Submit your project to the subversion repository. Do not forget to verify your submission on the web.