Description
The purpose of this challenge is examine the output and write the C++ source code that produces the given output and interaction.
Requirements
- You may use any combination of variable declarations, assignments, conditional statements, expressions, loops, etc
- Include <cstdlib> and <ctime> to enable the use of the built-in random number generator. See below on how to use the random number generator to have the computer produce integers within a given range.
#include <iostream> #include <cstdlib> #include <ctime> int main() { int v1, v2, v3; srand(time(NULL)); // these are examples on how to use the rand() function // v1, v2 and v3 are assigned random numbers below in the // ranges shown in the comments v1 = rand() % 100; // v1 in the range 0 to 99 v2 = rand() % 100 + 1; // v2 in the range 1 to 100 v3 = rand() % 30 + 1985; // v3 in the range 1985-2014 return 0; }
Sample Interaction / Output
$ [ run your program ] You have $20.00 in your account You must guess my number (it is between 1 and 100) You have a maximum of seven tries to guess my number OK, I have my number How much do you want to wager that you can guess it in seven attempts? 5.00 OK, guess my number: 30 Your number is higher than mine. You have six attempts left OK, guess my number: 20 Your number is lower than mine. You have five attempts left OK, guess my number: 24 Your number is higher than mine. You have four attempts left OK, guess my number: 22 You guessed it! You now have $25.00 in your account Play again (y/n)? y You have $25.00 in your account You must guess my number (it is between 1 and 100) You have a maximum of seven tries to guess my number OK, I have my number How much do you want to wager that you can guess it in seven attempts? 10.00 OK, guess my number: 40 Your number is lower than mine. You have six attempts left OK, guess my number: 55 Your number is lower than mine. You have five attempts left OK, guess my number: 65 Your number is lower than mine. You have four attempts left OK, guess my number: 75 Your number is lower than mine. You have three attempts left OK, guess my number: 85 Your number is lower than mine. You have two attempts left OK, guess my number: 95 Your number is lower than mine. You have one attempt left OK, guess my number: 100 Your number is higher than mine You failed to guess my number You now have $15.00 in your account Play again (y/n)? n $ [ back to the command prompt ]
LEGEND
PROGRAM OUTPUT
USER INPUT
FROM INPUT
CATALOG ID: CPP-BB0001
Print Requirements