I am new to this website, and coding as well, so please bear with me. I have a program that i'm trying to fortmat the output into a single line. The output should read :
HHHHHTTTTT
Number of Heads: 5
Number of Tails : 5
where the values change per the result of the coin flips.
here is the code:
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <iomanip>
using namespace std;
void flips(); // Function Prototype
int count; //initializing the counters
int countH=0;
int countT=0;
int flip;
int main()
{
srand((unsigned)time(0));
for(count=0; count<10; count++)
flips(); // Calling function flip()
cout <<"\n\n\n\t\tNumber of Heads: "<<countH<<endl;
cout <<"\t\tNumber of Tails: "<<countT<<endl<<endl<<endl;
return 0;
}
void flips() // Defination of flip() funtion
{
flip = (rand()%2)+1;
if (flip < 2)
{
cout <<"H";
countH++;
}
else
{
cout<<"T";
countT++;
}
}
this is what i get for output:
HHHHTHHHTH
Number of Heads: 8
Number of Tails: 2
Press any key to continue . . .
so my question is how do i center the first line ?
thanks.