Coin Flip (heads and tails display)

Hi, for my assignment I'm trying to output the users requested coin toss amount and then give them the amount of times they flipped heads and tails. I'm having a hard time trying to figure out how I should implement this.


#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int cointoss (void){
int randomNumber;
randomNumber = 1 + rand() % 2;
return randomNumber;


}
int main(){
int howManyTimes = 0 ;
int randomNumber = 0 ;
int heads = 0 ;
int tails = 0 ;

string headtail = "";

cout << "How many times do you want to toss the coin?\n";
cin >> howManyTimes ;

//srand((time(0)));

for(int i = 1; i<= howManyTimes; i++){
randomNumber = cointoss() ;
if (randomNumber == 1)
headtail = "0" ;
//tails = tails + 1 ;


else
headtail = "1" ;
//heads = heads + 1 ;
cout << headtail << endl;

//cout << "You flipped tails " << tails << " times." << endl;
//cout << "You flipped heads " << heads << " times." << endl;
}


return 0;
}


The program displays the heads and tails as 1 and 0. and im then supposed to cout a statement saying the amount of times for each.
You need to count home many heads and how many tails you get.

You have the counters declared, you just need to increment the correct one after each call to cointoss().

Also, you appear to have commented out the call to srand(). You'll need that.
Topic archived. No new replies allowed.