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 101 102 103 104 105 106 107 108 109 110 111 112 113
|
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <iomanip>
using namespace std;
int main()
{
srand((unsigned)time(0));
int num1, num2, num3, num4;
num1 = rand()%4+1;
num2=rand()%4+1;
while (num2 == num1)
num2 = rand()%4+1;
num3=rand()%4+1;
while (num3 == num1 || num3==num2)
num3 = rand()%4+1;
num4=rand()%4+1;
while (num4==num1 || num4==num2 || num4==num3 )
num4 = rand()%4+1;
cout << num1 << num2 << num3 <<num4;
int card1=num1 , card2=num2,card3=num3,card4=num4;
cout << setw(50) << "CARD SHUFFLING COMPLETED \n" <<endl;
cout << card1 << "\t" <<card2 << "\t" <<card3 << "\t" << card4 <<endl;
do
{
cout << endl << " (Player One), please pick a number from 1-4 to draw your card : \n" <<endl;
cin >> choice;
if (choice == card1)
{
num1 = rand()%3+1;
num2=rand()%3+1;
while (num2 == num1)
num2 = rand()%3+1;
num3=rand()%3+1;
while (num3 == num1 || num3==num2)
num3 = rand()%3+1;
card2=num1 , card3=num2 , card4=num3;
}
else if (choice == card2)
{
num1 = rand()%3+1;
num2=rand()%3+1;
while (num2 == num1)
num2 = rand()%3+1;
num3=rand()%3+1;
while (num3 == num1 || num3==num2)
num3 = rand()%3+1;
card1=num1, card3=num2, card4=num3;
}
else if (choice == card3)
{
num1 = rand()%3+1;
num2=rand()%3+1;
while (num2 == num1)
num2 = rand()%3+1;
num3=rand()%3+1;
while (num3 == num1 || num3==num2)
num3 = rand()%3+1;
card1=num1, card2=num2, card4=num3;
}
else if (choice == card4)
{
num1 = rand()%3+1;
num2=rand()%3+1;
while (num2 == num1)
num2 = rand()%3+1;
num3=rand()%3+1;
while (num3 == num1 || num3==num2)
num3 = rand()%3+1;
card1=num1, card2=num2, card3=num3;
}
else
cout << "Invalid number - There are only 4 shuffled. Please select 1-4 : ";
} while(choice!=1 && choice!=2 && choice!=3 && choice!=4 );
cout << num1 <<num2 << num3 ;
cout << "Cards reshuffled. /n" ;
cout << "Dear Player 2, please select your shuffled card from 1-4 : " <<endl;
cin >> choice2;
cout << "Player 1 chose card " << card1 << endl;
cout << "Player 2 chose card " << card2 <<endl;
}
|