/* easy_dice.c Program 4 Created by Nhung Blaschke on 2/9/15. Copyright (c) 2015 Nhung Blaschke. All rights reserved. */ #include #include #include /* Easy dice game The game consists of 7 rounds. In each round, the human throws a die three times. The human may roll three more if they don't like their score (the sum of the three rolls). Then the computer throws the die three times. The computer gets an additional roll if the human rolled the additional three. The winner of the round is the player who has the highest score. In case of a tie, the computer wins. The winner of the game is the player who has won the most rounds. */ void rollem (player,score,limit) char player[];int *score,limit; { int i,toss; *score=0; printf("\n%s's turn:\n\n",player); for (i=0;i<=limit;i++) { printf("%s throws a %d\n",player,toss=rand()%6+1); *score+=toss; } printf("\n%s's score is %d\n",player,*score); } int main() { int round,limit,humanWins,computerWins; int humanScore,computerScore; char choice[5]; humanWins=computerWins=0; srand((unsigned)time(NULL)); /* Play the rounds */ for (round=1;round<=7;round++) { printf("\nRound %d\n",round); rollem("Human",&humanScore,2); printf("\nTry again? (Y or N) "); scanf("%s",&choice); limit=2; if (choice[0]=='Y'||choice[0]=='y') { limit=3; rollem("Human",&humanScore,2); } rollem("Computer",&computerScore,limit); /* Determine winner of round */ if (humanScore>computerScore) { humanWins++;printf("\nHuman wins the round. "); } else { computerWins++;printf("\nComputer wins the round. "); } printf("Human: %d Computer: %d\n",humanWins,computerWins); } /* Determine winner of game */ if (humanWins>computerWins) { printf("\nWINNER!! The Human wins the game!\n"); } else { printf("\nThe Computer wins the game!\n"); } printf("\n");system("pause"); return 0; }