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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
|
#include <iostream> //I/O Library -> cout,endl
#include <iomanip> //Format Library
#include <cstdlib> //Rand/Srand
#include <ctime> //Time
#include <fstream> //File i/o
using namespace std;//namespace I/O stream library created
//User Libraries
//Global Constants
//Math, Physics, Science, Conversions, 2-D Array Columns
//Function Prototypes
//Execution Begins Here!
int main(int argc, char** argv) {
//Seed the random number function
srand(static_cast<unsigned int>(time(0)));
//Declare Variables
int numPlay,//Number of Players
winner,//Winner of the game
loser;//Who lost the game
int die1,die2,sum1,sum2,sum3,sum4,sum5,sum6,sum7,sum8,sum9;
int p1,p2,p3,p4,p5,p6,p7,p8,p9;//players in the game
int lives1=6,//Number of lives/person
lives2=6,
lives3=6,
lives4=6,
lives5=6,
lives6=6,
lives7=6,
lives8=6,
lives9=6;
cout<<"How many players are there from 2 to 10?\n";
cin>>numPlay;
do{
if(numPlay==2){
int die1={rand()%6+1}; //[1,6]
int die2={rand()%6+1}; //[1,6]
int sum1=die1+die2;
p1=sum1;
die1={rand()%6+1}; //[1,6]
die2={rand()%6+1}; //[1,6]
int sum2=die1+die2;
p2=sum2;
}
if(p1>p2){
lives2--;
}else{
lives1--;
}
}while(lives1>0 && lives2>0);
do{
if(numPlay==3){
int die1={rand()%6+1}; //[1,6]
int die2={rand()%6+1}; //[1,6]
int sum1=die1+die2;
p1=sum1;
die1={rand()%6+1}; //[1,6]
die2={rand()%6+1}; //[1,6]
int sum2=die1+die2;
p2=sum2;
die1={rand()%6+1}; //[1,6]
die2={rand()%6+1}; //[1,6]
int sum3=die1+die2;
p3=sum3;
}
if(p2>p1 && p3>p1)
lives1--;
if(p1>p2 && p3>p2)
lives2--;
if(p2>p3 && p1>p3)
lives3--;
}while(lives1>0 && lives2>0 && lives3>0);
do{
if(numPlay==4){
int die1={rand()%6+1}; //[1,6]
int die2={rand()%6+1}; //[1,6]
int sum1=die1+die2;
p1=sum1;
die1={rand()%6+1}; //[1,6]
die2={rand()%6+1}; //[1,6]
int sum2=die1+die2;
p2=sum2;
die1={rand()%6+1}; //[1,6]
die2={rand()%6+1}; //[1,6]
int sum3=die1+die2;
p3=sum3;
die1={rand()%6+1}; //[1,6]
die2={rand()%6+1}; //[1,6]
int sum4=die1+die2;
p4=sum4;
}
if(p2>p1 && p3>p1 && p4>p1)
lives1--;
if(p1>p2 && p3>p2 && p4>p2)
lives2--;
if(p2>p3 && p1>p3 && p4>p3)
lives3--;
if(p1>p4 && p2>p4 && p3>p4)
lives4--;
}while(lives1>0 && lives2>0 && lives3>0 && lives4>0);
do{
if(numPlay==5){
int die1={rand()%6+1}; //[1,6]
int die2={rand()%6+1}; //[1,6]
int sum1=die1+die2;
p1=sum1;
die1={rand()%6+1}; //[1,6]
die2={rand()%6+1}; //[1,6]
int sum2=die1+die2;
p2=sum2;
die1={rand()%6+1}; //[1,6]
die2={rand()%6+1}; //[1,6]
int sum3=die1+die2;
p3=sum3;
die1={rand()%6+1}; //[1,6]
die2={rand()%6+1}; //[1,6]
int sum4=die1+die2;
p4=sum4;
die1={rand()%6+1}; //[1,6]
die2={rand()%6+1}; //[1,6]
int sum5=die1+die2;
p5=sum5;
}
if(p2>p1 && p3>p1 && p4>p1 && p5>p1)
lives1--;
if(p1>p2 && p3>p2 && p4>p2 && p5>p2)
lives2--;
if(p2>p3 && p1>p3 && p4>p3 && p5>p3)
lives3--;
if(p1>p4 && p2>p4 && p3>p4 && p5>p4)
lives4--;
if(p1>p5 && p2>p5 && p3>p5 && p4>p5)
lives4--;
}while(lives1>0 && lives2>0 && lives3>0 && lives4>0 && lives5>0);
//Initialize
//Initial Variables
//Map/Process Input to Outputs
//Display outputs
if(numPlay==2){
cout<<lives2<<lives1<<endl;
}
if(numPlay==3){
cout<<lives1<<lives2<<lives3<<endl;
}
if(numPlay==4){
cout<<lives1<<lives2<<lives3<<lives4<<endl;
}
if(numPlay==5){
cout<<lives1<<lives2<<lives3<<lives4<<lives5<<endl;
}
//Exit program!
return 0;
}
|