Hello guys.
Please advice how to get a random number from the function. I have to "throw a coin" one hundred times and count heads and tails amount. I did it like this:
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<ctime.h>
#include<cstdlib.h>
#pragma hdrstop
int flip ();
//---------------------------------------------------------------------------
#pragma argsused
int main(int argc, char* argv[])
{ int heads = 0, tails = 0, fart ;
for (int i =1;i<=100;i++) {
fart = flip();
cout << fart << " ";
if (fart == 0)
heads++;
else
tails++;}
cout << heads << " " << tails;
getch();
return 0;
}
//---------------------------------------------------------------------------
int flip ()
{
randomize();
int mod = rand()%2;
return mod;
}
It doesn't matter if i use randomize() or srand(time(0)). The result is the same. It gives me either zeros or ones only while i need both. What am i doing incorrectly?