Return To CS 110 Home

Colour Theme   Font Size Options
 
   
   
   
Card Guessing

Card Guessing Game


Video Summary: https://youtu.be/rUoYh0XA4MI


In this exercise, you will create the greater than/less than card guessing game. In this game, a card is drawn, and the player guesses whether the next card will be greater than or less than that card. You can start from this solution to a previous exercise:


First, divide the features of the program into different functions:

  1. A function to generate a random number
  2. A function for the switch statement to assign the symbol
  3. A function to draw the card

After this:

  1. Create a function that will prompt the user to guess greater than or less than. You could use the symbols '<' and '>'
  2. Create a function to evaluate if the user guessed correctly
  3. Create a loop to keep drawing and guessing cards

You may loop the game infinitely or ask the user if they want to keep playing. When you are finished, your output might look like this:

-------
|♠    |
|  7  |
|    ♠|
-------
Will the next card be greater or less than this card?  Enter '<' or '>'<
-------
|♦    |
|  9  |
|    ♦|
-------
Your guess is incorrect
Will the next card be greater or less than this card?  Enter '<' or '>'<
-------
|♦    |
|  5  |
|    ♦|
-------
Your guess is correct
Will the next card be greater or less than this card?  Enter '<' or '>'>
-------
|♠    |
|  11 |
|    ♠|
-------
Your guess is correct
Will the next card be greater or less than this card?  Enter '<' or '>'
signal: terminated

Some hints:

Solution