CSE 202: Computer Science II, Winter 2018
Lab 2

You may use the following function in your program to generate a random integer.

#include <cstdlib> #include <ctime> unsigned int random_integer() { static bool is_seeded; if (!is_seeded) { std::srand(std::time(0)); is_seeded = true; } return std::rand(); }

For this lab, you will create a game where the user bets on dice rolls

In your program, the user starts off with 30 coins. The program will repeatedly do the following:

  1. If the user is out of coins, the program stops.
  2. The program displays how many coins the user has.
  3. The user chooses to pay 0, 1, 2, or 3 coins
  4. If the user chooses 0, then the program stops.
  5. The program will simulate a dice roll be generating and displaying 2 random integers, each being a value from 1 to 6.
  6. If both random integers end up having the same value, the user gains coins equal to 3 multiplied by the number of coins they paid.

Solution