Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h> // srand, rand
- #include <time.h> // time
- using namespace std;
- void rando();
- int main() {
- cout << "Rock Your World!\n" << endl;
- double balance; // Amount of money user is inputting
- //getting user to input starting amount
- cout << "Enter your starting balance (minimum of $1): " << endl;
- cin >> balance;
- // loop to make sure they enter the correct amount (min 1)
- if(balance < 1)
- {
- cout << "Invalid amount entered, try again\n";
- }
- else
- {
- cout << "Starting Balance: " << balance << "\n" << endl; //displaying balance user input
- }
- rando();
- return 0;
- }
- // generating random numbers
- void rando()
- {
- srand(time(NULL)); // generating a random seed
- int random = rand() % 6 + 1; //limiting random number generator between 1 and 6
- double test;
- test = (double)random; // turning random into a double so % will work with the if statement
- if(random % 2 == 0) // conditions for an even number rolled
- {
- cout << "Rolling...\n";
- cout << " Even rolled, you gain $1 \n";
- }
- else if(random % 2 == 1) // conditions for an odd number rolled
- {
- cout << "Rolling...\n";
- cout << "Odd rolled, you lose 1$ ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment