Contents

Description

The purpose of this lab will be to gain experience defining and invoking functions. We're going to update the code from last week. Here's the program description:

The program should start by randomly picking a number between 1 and 10 (I'll provide you with the code to do that). It will then give the user three chances to choose the right number. After each guess, you should tell the user whether they've guessed too high or too low. If they guess correctly, then they've won and you can exit the program. If they haven't guessed after three tries, then they loose.

The difference is, this week you need to have three functions besides main. I will give you the signatures, but you have to declare them, define them, and figure out how invoke them.

(Back to top)

Tasks

Do each of these things and have the professor check them out as you complete them.

  1. Update your flowchart from Lab 3; draw a rectangle around all of the steps that should go into a single function (see below for a list of functions you should be grouping your steps into); you can have boxes within boxes
  2. Update your code from Lab 3 with stubs (function declarations and empty definitions) for the following functions:
    • void runGuessingGame()
    • int generateRandomNumber(int range, int start)
    • int promptUserForInput()
    • bool checkGuess(int randomNumber, int guess)
  3. Incrementally implement the stubs in the order listed; make sure you compile after each step
  4. Show me the final version

Some more resources:

(Back to top)