after the 1st iteration the toss is 100 and then the iteration increases toss to 200 and then 300. Why is this happening i want toss to be made only hundred times. PLease help me.
#include <iostream>
using namespace std;
#include <cstdlib>
#include<ctime>
int toss(void);
int main(void)
{
srand(time(0));
int headcount=0;
int tailcount=0;
char ht;
loop:cout<<"press h for calling out head"<<endl<<"or t for calling out tail"<<'\n'<<"e for exiting game"<<'\n';
cin>>ht;
if(ht=='h'||ht=='t')
{
for(int i=0;i<100;i++)
{
int k=toss();
if(k==0)
{
cout<<"heads"<<endl;
headcount++;
}
else
{
tailcount++;
cout<<"tails"<<endl;
}
}
cout<<"the number of heads is "<<headcount<<endl;
cout<<"the number of tails is "<<tailcount<<endl;
if(headcount>tailcount)
{
cout<<endl<<"head wins"<<endl;
}
else
{
cout<<endl<<"tails wins"<<endl;
}
}
else if(ht=='e')
{
exit(0);
}
else
{
cout<<"wrong input";
}
cout<<"do you want to continue:press y for yes and press any key for quitting";
char ch;
cin>>ch;
if(ch=='y')
{
goto loop;
}
else
{
exit(0);
}
}
int toss(void)
{
return rand()%2;
}