I have a question for the following program: #include #include using namespace std; int rolldice(){ int r1, r2, s = 0; r1 = rand() % 6 + 1; cout


I have a question for the following program:


#include


#include


using namespace std;



int rolldice(){


int r1, r2, s = 0;


r1 = rand() % 6 + 1;


cout < "after="" rolling:="" "="">< r1=""><>


r2 = rand() % 6 + 1;


cout < "after="" rolling:="" "="">< r2=""><>


s = r1 + r2;


if(r1 == r2){


r1 = rand() % 6 + 1;


cout < "after="" rolling:="" "="">< r1=""><>


r2 = rand() % 6 + 1;


cout < "after="" rolling:="" "="">< r2=""><>


s += r1 + r2;


if(r1 == r2)


s = 1;


}


return s;


}



int findfirst(int pos[]){


int i, j = 0, m = pos[0];


for(i = 1; i < 4;="">


if(m <>


m = pos[i];


j = i;


}


}


return j;


}



int findlast(int pos[]){


int i, j = 0, m = pos[0];


for(i = 1; i < 4;="">


if(m > pos[i]){


m = pos[i];


j = i;


}


}


return j;


}



void calposition(int pos[], int sum[]){


int i, p, temp, j;


for(i = 0; i < 4;="">


if(sum[i] == 1 || sum[i] == 12)


pos[i] = 0;


else if(sum[i] == 4 && pos[i] > 1)


pos[i] -= 1;


else if(sum[i] == 7){


p = findfirst(pos);


if(pos[p] != pos[i]){


temp = pos[i];


pos[i] = pos[p];


pos[p] = temp;


}


}


else if(sum[i] == 11){


p = findlast(pos);


if(pos[p] != pos[i]){


temp = pos[i];


pos[i] = pos[p];


pos[p] = temp;


}


}


else{


if((pos[i] + sum[i]) <=>


pos[i] += sum[i];


}


for(j = 0; j < 4;="">


if(i != j){


if(pos[i] == pos[j])


pos[j] = 0;


}


}


}


}



void display(int pos[]){


int i,j, k = 1, m;


for(i = 1; i <= 51;="">


cout <>


cout <>


for(i = 1; i <= 5;="">


for(j = 1; j <= 10;="">


if(k == pos[0])


cout < "|_p"="">< 1=""><>


else if(k == pos[1])


cout < "|_p"="">< 2=""><>


else if(k == pos[2])


cout < "|_p"="">< 3=""><>


else if(k == pos[3])


cout < "|_p"="">< 4=""><>


else


cout <>


k++;


}


cout < "|"=""><>


}


}



int findwinner(int pos[]){


int i;


for(i = 0; i < 4;="">


if(pos[i] == 50){


break;


}


}


if(i == 4)


return 0;


else


return (i + 1);


}



int main() {


   int pos[4];


   int sum[4];


   int i, temp, winner;


   char choice = 'y';


   cout < "lets="" play,="" sorry!"=""><>



   while(choice == 'y' || choice == 'Y'){


   pos[0] = pos[1] = pos[2] = pos[3] = 0;


   while(true){


   for(i = 0; i < 4;="">


   cout < "player="" "="">< i="" +="" 1="">< "="" is="" rollong."=""><>


   sum[i] = rolldice();


   }


   calposition(pos, sum);


   display(pos);


winner = findwinner(pos);


   if(winner > 0){


   cout < "player="" "="">< winner="">< "="" is="" winner!!"=""><>


   break;


   }


   }


   cout < "wanna="" play="" again?="" (y/n)"=""><>


   cin >> choice;


   }


   return 0;


}




How did it display the player's position after every roll?




Jun 09, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here