#include <stdio.h>
#include <stdlib.h>
int twento(void);
int main(int argc, char *argv[])
{
int number1,number2,sum1=0,sum2=0;
do{
printf("Player 1 you start to play:\n");
number1=twento();
sum1 = number1 + sum1;
printf("Player1 Your sum is %d\n",sum1);
printf("Player2 Your turn to play:\n");
number2=twento();
sum2=number2+sum2;
printf("Player2 Your sum is: %d\n",sum2);
if (sum1==21)printf("\nPlayer1 You win");
else if(sum2==21)printf("Player2 You win");
else if(sum1>21)printf("\n Player 1 You Lose");
else if(sum1>21)printf("\n Player 2 You Lose");
}while(sum1<=21 || sum2<=21);
system("PAUSE");
return 0;
}
int twento(){
srand(time(NULL));
return rand()%9+1;
}
Can anyone tel me y this program does run until the sum is greater than 21 ?
The Question was ::
Qu.4 Write down a C program to play the game of 'twenty-one' between two players.
The game consists of buying numbers in the range 1 to 9. The numbers are added
until the sum equals to 21. The player to score 21 first wins the game.