-
Notifications
You must be signed in to change notification settings - Fork 0
/
casinogame.cc
94 lines (71 loc) · 2.55 KB
/
casinogame.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//Author: Zach Naymik
//Date: February 10, 2022
//Description: This program allows the user to play a gambling game in which they try to guess a number to win 10x their money
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main()
{
//Variable Declaration
double user_balance, user_bet;
int user_guess, winning_number;
char play_again;
cout << "Welcome to the Casino Game" << endl;
//Loop to get balance deposit and verify that amount is valid
do
{
cout << "Enter how much money you would like to deposit $";
cin >> user_balance;
if (user_balance < 0)
{
cout << "Invalid amount, please try again" << endl;
}
} while (user_balance < 0);
cout << "Your balance is: $" << user_balance << endl;
do
{
//Loop to define bet amount
do
{
cout << "Enter amount you would like to bet: $";
cin >> user_bet;
if ((user_bet < 0) || (user_bet > user_balance))
{
cout << "Invalid bet amount, please try again" << endl;
}
} while ((user_bet < 0) || (user_bet > user_balance));
cout << "Your bet amount is $" << user_bet << endl;
//Loop to define number guessed
do
{
cout << "Enter the number you would like to bet on (0-9): ";
cin >> user_guess;
if ((user_guess < 0) || (user_guess > 9))
{
cout << "Invalid guess, please try again" << endl;
}
} while ((user_guess < 0) || (user_guess > 9));
//Generates the winning number with random function
winning_number = rand() % 10;
//Statements to decide if user is a winner/loser and updating balance based on win or loss
if (user_guess == winning_number)
{
user_balance += (user_bet * 10);
cout << "Congratulations, you won!" << endl;
cout << "Your new balance total is: $" << user_balance << endl;
}
else
{
user_balance -= user_bet;
cout << "Sorry, you lost." << endl;
cout << "Your new balance total is: $" << user_balance << endl;
}
cout << "Would you like to play again? (y/n) ";
cin >> play_again;
} while ((play_again == 'y') && (user_balance > 0));
cout << "You decided not to play again, or you need to deposit more money!" << endl;
}