-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDice gusesing.cpp
66 lines (52 loc) · 1.79 KB
/
Dice gusesing.cpp
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
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void playGame() {
int playerRoll, computerRoll;
int playerScore = 0, computerScore = 0;
int rounds;
char playAgain;
srand(static_cast<unsigned int>(time(0)));
cout << "Welcome to the Dice Game!" << endl;
cout << "Enter the number of rounds you want to play: ";
cin >> rounds;
for (int round = 1; round <= rounds; ++round) {
cout << "\nRound " << round << "!" << endl;
playerRoll = rand() % 6 + 1;
cout << "You rolled: " << playerRoll << endl;
computerRoll = rand() % 6 + 1;
cout << "Computer rolled: " << computerRoll << endl;
if (playerRoll > computerRoll) {
cout << "You win this round!" << endl;
++playerScore;
} else if (computerRoll > playerRoll) {
cout << "Computer wins this round!" << endl;
++computerScore;
} else {
cout << "It's a tie this round!" << endl;
}
}
cout << "\nGame Over!" << endl;
cout << "Final Scores:" << endl;
cout << "You: " << playerScore << endl;
cout << "Computer: " << computerScore << endl;
if (playerScore > computerScore) {
cout << "Congratulations! You are the overall winner!" << endl;
} else if (computerScore > playerScore) {
cout << "The computer wins this time. Better luck next time!" << endl;
} else {
cout << "It's an overall tie!" << endl;
}
cout << "Do you want to play again? (y/n): ";
cin >> playAgain;
if (playAgain == 'y' || playAgain == 'Y') {
playGame();
} else {
cout << "Thanks for playing! Goodbye!" << endl;
}
}
int main() {
playGame();
return 0;
}