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:

  • You could use the same function to generate the card and suit if you pass the int you want to use modulus with. This function would return int, and you would need to add 1 for the card value.
  • The function to evaluate if the user is correct or not could either return a string result or be a void that prints the result within the function
  • The function prompting input will either need a string return, or have the string passed by reference to store the user's answer
  • You will need variables for two card numbers - the card the user saw first, and the second card they bet on. At the end of the loop, update the previous card to the new card
  • You will need to declare the enum for the suit globally if you want to pass an enum datatype

Solution