Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //============================================================================
- // Name : 12.cpp
- // Author :
- // Version :
- // Copyright : Your copyright notice
- // Description : Hello World in C++, Ansi-style
- //============================================================================
- #include <iostream>
- using namespace std;
- int printRounds();
- int main() {
- int round[] = {0, 0, 0};
- int gameCountIn;
- int gameCountSys = 0;
- int gameSummary[] = {0, 0, 0};
- cin >> gameCountIn;
- do {
- gameCountSys++;
- cout << " *** GAME " << gameCountSys << "***\n"
- "Roll Player 1 Player 2\n";
- switch(printRounds()) {
- case 1:
- cout << "\n\nPlayer one wins!\n\n";
- gameSummary[0]++;
- break;
- case 2:
- cout << "\n\nPlayer two wins!\n\n";
- gameSummary[1]++;
- break;
- case 3:
- cout << "\n\nIt's a tie!\n\n";
- gameSummary[2]++;
- break;
- }
- } while(gameCountIn != gameCountSys);
- cout << " *** GAME SUMMARY ***\nPlayer 1 Player 2 Ties\n"
- << " " << gameSummary[0] << " " << gameSummary[1] << " "; gameSummary[2];
- return 0;
- }
- int printRounds(int round[]) { //will return who won
- round[0]++;
- round[1] += rand() % 6 + 1;
- round[2] += rand() % 6 + 1;
- cout << round[0] << " " << round[1] << " " << round[2] << endl;
- if (round[0] > 3) { //In rounds after 3, there is a potential for a player to exceed 21
- if (round[1] > 21) {
- if (round[2] > 21) {
- return 3; //tie
- } else {
- return 2; //1 wins
- }
- } else if (round[2] > 21) {
- return 1; //1 wins
- } else if (round[1] == 21) {
- return 1; //1 wins
- } else if (round[2] == 21) {
- return 2; //2 wins
- }
- }
- printRounds();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement