Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <cstdlib>
- using namespace std;
- // Functions have four parts: body, name, parameters, return type
- string flip_coin()
- {
- int random_number = rand() % 2;
- if(random_number == 0)
- {
- return "HEADS"; // stops flip_coin and sends HEADS to where we left off
- }
- else
- {
- return "TAILS"; // stops flip_coin and sends TAILS to where we left off
- }
- }
- int main ()
- {
- int num_seconds = time(NULL);
- srand(num_seconds);
- int num_flips;
- cout << "User - how many coin flips do you want?" << endl;
- cin >> num_flips;
- for (int x = 1; x <= num_flips; x++)
- {
- cout << flip_coin() << endl; // flip coing simplifies to HEADS or TAILS
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement