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>
using namespace std;
void play22();
int pl_1_play(const string &pl_1, const string &pl_2, int count=0);
int pl_2_play(const string &pl_1, const string &pl_2, int count);
int main(){
play22();
return 0;
}
void play22(){
cout << "Welcome to TwentyTwo Game: \n";
string pl_1, pl_2;
cout << "Name of player1 : ";
getline(cin, pl_1);
cout << "Name of player2 : ";
getline(cin, pl_2);
pl_1_play(pl_1, pl_2);
}
int pl_1_play(const string &pl_1, const string &pl_2, int count){
int i;
cout << pl_1 << ", enter number (1,2,3) ";
cin >> i;
if(i!=1 && i!=2 && i!=3){
cout << "wrong input. try again.\n";
pl_1_play(pl_1, pl_2, count);
}
else{
count += i;
cout << "Sum = " << count << "\n";
if(count<22) {
int val = pl_2_play(pl_1, pl_2, count);
if(val==1) return 0;
}
else{
cout << "Sum greater or equal to 22, " << pl_2 << " wins.\n";
return 0;
}
}
}
int pl_2_play(const string &pl_1, const string &pl_2, int count){
int i;
cout << pl_2 << ", enter number (1,2,3) ";
cin >> i;
if(i!=1 && i!=2 && i!=3){
cout << "wrong input. try again.\n";
pl_2_play(pl_1, pl_2, count);
}
else{
count+=i;
cout << "Sum = " << count << "\n";
if(count<22) pl_1_play(pl_1, pl_2, count);
else{
cout << "Sum greater or equal to 22, " << pl_1 << " wins.\n";
return 1;
}
}
}
|