Guest User

Untitled

a guest
Nov 16th, 2022
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h> // srand, rand
  3. #include <time.h> // time
  4. using namespace std;
  5.  
  6. void rando();
  7.  
  8. int main() {
  9. cout << "Rock Your World!\n" << endl;
  10. double balance; // Amount of money user is inputting
  11.  
  12. //getting user to input starting amount
  13.  
  14. cout << "Enter your starting balance (minimum of $1): " << endl;
  15. cin >> balance;
  16.  
  17. // loop to make sure they enter the correct amount (min 1)
  18.  
  19. if(balance < 1)
  20. {
  21. cout << "Invalid amount entered, try again\n";
  22. }
  23. else
  24. {
  25. cout << "Starting Balance: " << balance << "\n" << endl; //displaying balance user input
  26. }
  27. rando();
  28.  
  29.  
  30.  
  31.  
  32. return 0;
  33. }
  34.  
  35. // generating random numbers
  36.  
  37. void rando()
  38. {
  39. srand(time(NULL)); // generating a random seed
  40.  
  41. int random = rand() % 6 + 1; //limiting random number generator between 1 and 6
  42. double test;
  43. test = (double)random; // turning random into a double so % will work with the if statement
  44.  
  45. if(random % 2 == 0) // conditions for an even number rolled
  46. {
  47. cout << "Rolling...\n";
  48. cout << " Even rolled, you gain $1 \n";
  49. }
  50. else if(random % 2 == 1) // conditions for an odd number rolled
  51. {
  52. cout << "Rolling...\n";
  53. cout << "Odd rolled, you lose 1$ ";
  54. }
  55.  
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment