Created
October 24, 2011 17:42
-
-
Save b-adams/1309607 to your computer and use it in GitHub Desktop.
Program 5 Specs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
@brief Run the guessing game, using a FOR loop. | |
@param rounds How many guesses the user gets | |
@param low The smallest number that might be the target | |
@param high The biggest number that might be the target | |
@param target The number the user should guess | |
@returns how many times the user guessed correctly. | |
The user is prompted to enter a number between low and high. If correct, select a new target randomly between low and high, not the victory, and congratulate the user. Otherwise, change high or low (as appropriate) to the user's guess. | |
This function uses a FOR loop to run the game logic rounds-many times. | |
@todo has a local variable called <code>guessCounter</code> which is initialized to zero. | |
@todo Run the loop <code>rounds</code> many times. | |
@todo In the loop, prompt the user to enter a number between <code>low</code> and <code>high</code>. | |
@todo In the loop, if the user's number matches <code>target</code>, print out a congratulation message, increment <code>guessCounter</code> then set <code>target</code> to a new random number between <code>low</code> and <code>high</code>. | |
@todo In the loop, if the user's number is bigger than the target, set <code>high</code> to be the user's guess-1, and tell them they guessed too high. | |
@todo In the loop, if the user's number is smaller than the target, set <code>low</code> to be the user's guess+1, and tell them they guessed too low. | |
@todo After the above has been done <code>rounds</code> times, return <code>guessCounter</code> | |
*/ | |
int doGameF(int rounds, int low, int high, int target); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
@brief Main function - entry point for the program | |
@param argc How many command-line arguments were entered | |
@param argv The command line arguments | |
@returns 0 if all went well | |
@todo Has a local variable called <code>timesGuessed</code> that is initialized to 0. | |
@todo Prompts the user to enter a number between 0 and 50, and stores that result in a variable called <code>lowEnd</code> | |
@todo Prompts the user to enter a number between 50 and 100, and stores that in <code>highEnd</code> | |
@todo Picks a random number between <code>lowEnd</code> and <code>highEnd</code>, and stores that in <code>guessMe</code> | |
@todo Calls doGameF with arguments <code>20, lowEnd, highEnd, guessMe</code>. The returned result should be stored in <code>timesGuessed</code> | |
@todo Reports to the user how many times they correctly guessed the answer. | |
@todo Calls doGameR with arguments <code>20, lwoEnd, highEnd, guessMe</code>. The returned result should be stored in <code>timesGuessed</code> | |
@todo Reports to the user how many times they correctly guessed the answer. | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@todo has a function <code>int getInputBetween(int low, int high)</code> which prompts the user to enter a number between <code>low</code> and <code>high</code>, and either returns the value they entered (if the value is in the specified range) or says something snarky and then returns the result of calling <code>getInputBetween</code> again. | |
@todo has a function <code>int randInRange(int low, int high)</code> that returns a random number between <code>low</code> and <code>high</code>. See section 4.5, page 191-198, for starter information. See me for additional help. | |
@todo Has two functions, <code>int doGameF(int rounds, int low, int high, int target)</code> and <code>int doGameR(int rounds, int low, int high, int target)</code>, as documented below | |
@todo Has a main function that works as documented below |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
@brief Run the guessing game, using RECURSION. | |
@param rounds How many guesses the user gets | |
@param low The smallest number that might be the target | |
@param high The biggest number that might be the target | |
@param target The number the user should guess | |
@returns how many times the user guessed correctly. | |
The user is prompted to enter a number between low and high. If correct, select a new target randomly between low and high, not the victory, and congratulate the user. Otherwise, change high or low (as appropriate) to the user's guess. | |
This function uses RECURSION to run the game logic rounds-many times. | |
@todo Has local variables <code>newTarget, userGuess</code> | |
@todo if <code>rounds</code> is less than 1, return 0 (if there aren't any rounds, you can't have any right guesses!). Otherwise... | |
@todo prompt the user to enter a number between <code>low</code> and <code>high</code>. | |
@todo if the user's number matches <code>target</code>, print out a congratulation message, set <code>newTarget</code> to a random number between <code>low</code> and <code>high</code>, and return one more than the result of calling <code>doGameR</code> with arguments <code>rounds-1, low, high, newTarget</code>. | |
@todo if the user's number is bigger than the target, return the result of calling <code>doGameR</code> with arguments <code>rounds-1, low, userGuess-1, target</code> | |
@todo if the user's number is smaller than the target, return the result of calling <code>doGameR</code> with arguments <code>rounds-1, userGuess+1, high, target</code> | |
*/ | |
int doGameR(int rounds, int low, int high, int target); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment