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 95 96 97 98 99 100
|
//Task 2: Card game problem solving
#include <iostream>
#include "Header.h"
#include <math.h>
#include <time.h>
#include <string>
using namespace std;
int main()
{
int p1card = 0, p2card = 0, count = 0;
int p1point = 0, p2point = 0;
int p1score = 0, p2score = 0;
srand(time(NULL)); //Initalise random seed
string player1, player2;
cout << "Enter player 1 name:\t";
getline(cin, player1);
cout << "Enter player 2 name:\t";
getline(cin, player2);
do
{
p1card = rand() % 13 + 1;
p2card = rand() % 13 + 1;
count++;
/*if (p1score == 1) {
return('Ace');
}
else if (p1score == 11) {
return('Jack');
}
else if (p1score == 12) {
return('Quen');
}
else if (p1score == 13) {
return('King');
}*/
cout << "\nRound no.\t" << count << endl;
cout << "==================";
cout << endl << player1 << " was dealt: " << p1card;
cout << endl << player2 << " was dealt: " << p2card << endl;
if (p1card == p2card)
{
cout << "Round " << count << " ended in a draw: " << endl;
}
else if (p1card > p2card)
{
cout << player1 << " wins the round!" << endl;
p1score++;
}
else if (p2card > p1card)
{
cout << player2 << " wins the round!" << endl;
p2score++;
}
} while (count != 26);
p1(p1score, p2score, player1, player2);
p2(p1score, p2score, player1, player2);
cout << endl << endl;
system("PAUSE");
return 0;
}
void p1(int p1score, int p2score, string player1, string player2)
{
if (p1score > p2score)
{
cout << "\n\nFinal scores \n";
cout << "================\n";
cout << player1 << " score: " << p1score << endl;
cout << player2 << " score: " << p2score << endl;
cout << player1 << " wins the game! Goodbye!\n";
}
}
void p2(int p1score, int p2score, string player1, string player2)
{
if (p2score > p1score)
{
cout << "\n\nFinal scores \n";
cout << "================\n";
cout << player1 << " score: " << p1score << endl;
cout << player2 << " score: " << p2score << endl;
cout << player2 << " wins the game! Goodbye!\n";
}
}
|