program3 - /Tom Nanke /CIS150-001 /10/30/07 /Program 3...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
//Tom Nanke //CIS150-001 //10/30/07 //Program 3 //This program plays the game of pig. This is a game in which two players take turns rolling a six-sided die and the first player //to reach 100 points wins. In this game, however, the two players are a human player and a computer player. The //human player takes the first roll, and if he/she rolls from 2-6, he/she can choose to roll again or hold. If he/she decides to //hold, then the sum of all the rolls from the current turn is stored into his/her total score of the game. If a 1 is rolled, //however, the user's turn ends and no new points are added to his/her total game score. Once the user's turn is over, either //because of a hold or a 1 is rolled, then it becomes the computer's turn. To start, the computer keeps rolling a die until it //either rolls a 1 or gets a total sum of 20 or more, in which case it then holds. Then it would once again become the user's //turn, and after his/her turn, the computer keeps trying to roll until it reaches a 100, going back to last held value if it //rolls a one. The expected input is the user's selection of whether to roll or hold. The expected output is the total scores //at each turn, and then the winner of the game. #include <iostream> #include <ctime> //Here I include both ctime and time.h so that I get generate different random numbers for the human #include <time.h> //roll and for the computer roll. using namespace std; int humanTurn(int &humanTotalScore); //function prototype: This function calculates the human's score for a single turn. //pre-cond: The game has started. //post-cond: Returns a value for the total turn score to be added to the human's total game score. //The input parameter is the total game score for the human. int computerTurn(int &computerTotalScore); //function prototype: This function calculates the computer's score for a single turn. //pre-cond: The human has already rolled and either held or rolled a 1.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 6

program3 - /Tom Nanke /CIS150-001 /10/30/07 /Program 3...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online