I am so close to finsihing my homework im on last programmign assignment. I have the program written but i cant figure out what to take from main and put into my flip function. the teacher said it should only contain one lineof code. Anbody have any ideas?Which is :
Write a C++ program that uses the rand(), the srand(), and time() functions from the cstdlib and ctime libraries to simulate coin tossing. Your program should ask the user how many times the coin will be tossed. For each toss of the coin, the program should keep track of which side of the coin (e.g. Heads or Tails) appears, and it should count the total for each side. At the end ot tossing the coin the user-specified number of times, the program should print the results. The program should call a separate function named flip() that takes no arguments and returns 0 for tails and 1 for heads.
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
// Function prototype
unsigned getFlip();
int main()
{
// Variables
unsigned toss;
unsigned heads = 0;
unsigned tails = 0;
srand(time(0));
cout<< "Please enter how many times you'd like to flip the coin"<<endl;
cin>> toss;
for (unsigned i = 0; i < toss; i ++)
{
if (rand() % 2)
{
tails ++;
}
else
{
heads ++;
}
}
// How many times the coin hit heads and tails
cout<<"You have flipped tails "<<tails<<" times"<<endl;
cout<<"You have flipped heads "<<heads<<" times"<<endl;
//Initializing the time, and the total number of flips.
unsigned total = 0;
total = heads + tails;
time_t rawtime;
time ( &rawtime );
cout<<"The day of "<<ctime (&rawtime)<<"You flipped the coin "<<total;
cout<<" number of times"<<endl;
system("pause");
return 0;
}
// function flip
// returns 0 for tails and 1 for heads
unsigned getFlip()
{
}