all right, this is an exercise i was given at school:
you have to write a dos program in c++ where you ask the user how many times 1 dice should be thrown.
the throwing should be done in a function, no problems so far, here's my code all variables are declared properly, so is the function prototype and the headerfiles are ok:
cout<<"how many times?"<<endl;
cin>>times;
for (int i=0; i<=times; i++)
{result=throwdice();
cout<<result
}
int throwdice()
{
int result;
randomize();
result=random(6)+1;
return result;
}
you have to calculate the percentage of 1, 2, 3, 4... thrown but that's not the problem.
the function works but if, for example i let the program throw the dice 3 times i always get the same result; the output of the function is three times the same, it seems that the program refuses to choose the numbers randomly three times, only the first time.
i hope some of you understand my explanation of the problem and would somebody please help me with this?
thanks
stijn



LinkBack URL
About LinkBacks


