I have to make a game of craps and towards the end, I have to do some probability. Here is my code so far. I want it so that the loop repeats 1000 times and looks for the 'probNumb' that the user entered. I am not sure if did this right but lets say I entered the number 5. This is what I get.
"Out of 1000 times, 5 was rolled 1000 times."
So, its not counting how many times 5 was rolled. I am not allowed to use break or continue statements, only loops and if else.
cout << "What number do you want the probability of ?";
cin >> probNumb;
while (probCount < 1000)
{
ranNumb= 1 + (rand() % (5 + 1));
ranNumb2= 1 + (rand() % (5 + 1));
ranNumbFin = ranNumb + ranNumb2;
probCount++;
if (ranNumbFin = probNumb)
probNumbCount++;
}
cout << "Out of 1000 times, " << probNumb << " was rolled "
<< probNumbCount << "times." << endl;
if (ranNumbFin = probNumb)
is either a typo or should use ==
It's 1000 because the assignment returns the value assigned and since that's always non-zero in this case, it's always true.
it's a typo
if (ranNumbFin = probNumb)
should be
if (ranNumbFin == probNumb)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With