Starting from:

$25

COMP1400-Lab 5 Programming with Loops Solved

HI-LO game: A random number will be generated. Then, the program prompts for guesses until the user is correct, or has made 10 wrong guesses. After each guess, the program indicates whether the guess was too high, too low, or correct. Once the round has ended, either by a correct guess or by using up the 10 guesses, the program displays the current status. Assuming the random number is 48 (a number between 1 and 50), a sample interaction is shown below

                     

Enter your guess (between 1 and 50): 30

Too low …

Enter your guess (between 1 and 50): 50

Too high …

Enter your guess (between 1 and 50): 48 Correct, the number was 48.
 

If the user entered more than 10 wrong guesses:

 

                    Sorry, the number was 48.

 

Part A: RAPTOR Exercise

a)    Understand more about RAPTOR by watching the video clip about how to work with loops.

b)    Start RAPTOR and create the flowchart of HI-LO game.

c)     Save the flowchart to a file named “guessGame.rap” in the working directory on the PC you are using.

d)    Demonstrate the guessGame.rap file to GA/TAs and run with different input values. 

Hint: To generate a random number between 1 and 50 using Raptor, use the following assignment statement

 

goal ß floor((Random*50)+1)
 

For more information, watch the video clip about how to generate a random number Using Raptor

 

Part B: C Programming Exercise

 

a)    Implement the algorithm as represented by “guessGame.rap”, and write an equivalent C program that accomplishes what the flowchart does.

b)    Save your program to a file named “guessGame.c” in the working directory on the PC you are using. 

c)     Demonstrate the guessGame.c file to GA/TAs and run with different input values.

 

Hint: To generate a random number between 1 and 50 in C, first, add  #include <stdlib.h to your code and then use the following statement:

 int goal = rand( ) % 50 + 1;

More products