Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. #include <iostream> // for i/o
  2. #include <time.h> // for time and srand
  3. using namespace std;
  4.  
  5.  
  6. void GetRoll(float&, float&); //first void function
  7. float CalcSum(float, float); // value returning function
  8. void PrintRoll(float, float, float); // second void function
  9.  
  10. int main()
  11. {
  12. float die1, die2, sum = 0, sum2 = 0; // variables used
  13. srand(time(0)); // for random number operation
  14. cout << "This program will perform a game of craps. It will roll two dice and determine the outcome." << endl; // brief explantaion of the program
  15.  
  16. GetRoll(die1, die2); //calling first void function (to roll two dice)
  17. sum = CalcSum(die1, die2); // calling value returning function (to add the two dice together)
  18. PrintRoll(die1, die2, sum); // calling second void function (print out the sum and the outcome of the game0
  19.  
  20.  
  21. return 0; //end program
  22. }
  23.  
  24. void GetRoll(float& d1, float& d2) // code for the first void function to obtain 2 dice rolls.
  25. {
  26. d1 = rand() % 6 + 1;
  27. d2 = rand() % 6 + 1;
  28. return;
  29. }
  30.  
  31. float CalcSum(float d1 , float d2) // code for the value returning function to add the two dice rolled
  32. {
  33. float sum;
  34. sum = d1 + d2;
  35.  
  36. return sum;
  37. }
  38.  
  39. 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
  40. {
  41.  
  42. cout << "You rolled a " << d1 << " and a " << d2 << "." << endl; //print out the numbers rolled from dice
  43.  
  44.  
  45. if ((sum == 2) || (sum == 3) || (sum == 12))
  46. {
  47. cout << "Your sum is, " << sum << ". You lose." << endl; // nested if/else statement to determine the outcome of the game
  48. }
  49.  
  50. else if ((sum == 7) || (sum == 11))
  51. {
  52. cout << "You sum is, " << sum << ". You win." << endl;
  53. }
  54.  
  55. else
  56. {
  57. cout << "You sum is, " << sum << ". You have, " << sum << " points." << endl;
  58.  
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement