//Charlotte Davies-Kiernan           CS1A                  Chapter 6 P. 371 #8
//
/******************************************************************************
 * 
 * Display Coin Toss Simulator
 * ____________________________________________________________________________
 * This program will display a coin toss simulator that displays the tossing
 * of a coin the amount of times that is inputted and displays randomly, 
 * either heads or tails.
 * ____________________________________________________________________________
 * Input
 *   tosses     //The amount of times the coin will be tossed
 * Output
 *   result     //The result of the toss, either heads or tails
 *****************************************************************************/
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
using namespace std;
//Function Prototype
void coinToss ();
 
int main() {
//Data Dictionary
   int tosses;      //INPUT - The amount of times the coin will be tossed
   int result;      //OUTPUT - The result of the toss, either heads or tails
//Random Number Generator
srand(time(0));
 
cout << "Coint Toss Simulator: " << endl;
cout << "How many times should the coin be tossed? " << endl;
cin >> tosses;
if (tosses < 1){
	cout << "Invalid input. Please enter a positive integer: " << endl;
	cin >> tosses;
}
cout << "Tossing the coin " << tosses << " times..." << endl;
 
//Simulate coin tosses
for (int i = 1; i <= tosses; i++){
	cout << "Toss " << i << ": ";
	coinToss();
}
cout << "Simulation complete!" << endl;
return 0;
}
//Coin Toss Function
void coinToss (){
	int result = rand() % 2 + 1;
	if (result == 1)
	    cout << "Heads" << endl;
	else 
	    cout << "Tails" << endl;
}