Hi,
i'm doing a function to "flip a coin" and every time i try to start the program it works fine only if the code has a casual cout.
I'm using visual studio.
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <cstdlib>
using std::rand;
using std::srand;
#include <ctime>
using std::time;
int flip();
int main()
{
int testa = 0;//0
int croce = 0;//1
for (int i = 0; i < 100000; i++)
{
if (flip()== 0)
testa++;
else
croce++;
}
cout << "Testa: " << testa << endl << "Croce: " << croce << endl;
return 0;
}
int flip()
{
int porcodio;
srand(time(0));
porcodio = rand() % 2;
//cout << "porcodio" << endl; //here if i use this cout the function
//works
return porcodio;
}
my output without cout:
Testa: 100000
Croce: 0
my output with cout:
porcodio
porcodio
porcodio
...
Testa: 58010
Croce: 41990