Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream> // for i/o
- #include <time.h> // for time and srand
- using namespace std;
- void GetRoll(float&, float&); //first void function
- float CalcSum(float, float); // value returning function
- void PrintRoll(float, float, float); // second void function
- int main()
- {
- float die1, die2, sum = 0, sum2 = 0; // variables used
- srand(time(0)); // for random number operation
- cout << "This program will perform a game of craps. It will roll two dice and determine the outcome." << endl; // brief explantaion of the program
- GetRoll(die1, die2); //calling first void function (to roll two dice)
- sum = CalcSum(die1, die2); // calling value returning function (to add the two dice together)
- PrintRoll(die1, die2, sum); // calling second void function (print out the sum and the outcome of the game0
- return 0; //end program
- }
- void GetRoll(float& d1, float& d2) // code for the first void function to obtain 2 dice rolls.
- {
- d1 = rand() % 6 + 1;
- d2 = rand() % 6 + 1;
- return;
- }
- float CalcSum(float d1 , float d2) // code for the value returning function to add the two dice rolled
- {
- float sum;
- sum = d1 + d2;
- return sum;
- }
- void PrintRoll(float d1, float d2, float sum) // code for the second void function to print out the sum and the outcome of the game
- {
- cout << "You rolled a " << d1 << " and a " << d2 << "." << endl; //print out the numbers rolled from dice
- if ((sum == 2) || (sum == 3) || (sum == 12))
- {
- cout << "Your sum is, " << sum << ". You lose." << endl; // nested if/else statement to determine the outcome of the game
- }
- else if ((sum == 7) || (sum == 11))
- {
- cout << "You sum is, " << sum << ". You win." << endl;
- }
- else
- {
- cout << "You sum is, " << sum << ". You have, " << sum << " points." << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement