Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <algorithm>
- void game() {
- std::cout << "[*] How much money do you have? ";
- int user_money; std::cin >> user_money;
- int user_bet, user_guess, toss;
- while (user_money > 0) {
- std::cout << "[*] Place a bet. ";
- std::cin >> user_bet;
- if (user_bet > user_money) {
- std::cout << "Your bet was too large! Try again..." << std::endl;
- continue;
- }
- while (true) {
- std::cout << "Guess: 0 for heads, 1 for tails. ";
- std::cin >> user_guess;
- toss = rand() % 2;
- if (user_guess >= 0 && user_guess <= 1) {
- std::cout << "You guessed " << (user_guess == 0 ? "heads" : "tails")
- << " and were ";
- if (toss == user_guess) {
- std::cout << "correct!";
- user_money += user_bet;
- } else {
- std::cout << "incorrect!";
- user_money -= user_bet;
- }
- std::cout << std::endl;
- break;
- } else {
- std::cout << "Invalid guess. Try again...";
- }
- }
- std::cout << "You now have $" << user_money << ".\n";
- }
- std::cout << "You're out of money." << std::endll;
- }
- int main() {
- std::cout << "[*] Heads or Tails [*]" << std::endl
- << "You will bet on the outcome of a coin toss." << std::endl
- << "You can only bet as much as you have." << std::endl;
- game();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement