I think I might be repeating some of what I said in your other topic, but I'll tell you everything I see is wrong (which may not be all that's wrong with it).
int get_tri(int&)
Not exactly anything wrong here, but it's pointless for you pass a variable to your get_tri function. You don't even use it. Or actually you do, but there's no reason to use it.
float tri_prob(int, int, float&)
Same as above, there's really no reason for you to be passing your prob variable to this function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
do
{
cout << "Enter amount of rods to be dropped:"<< endl;
cin >> num_rods;
for (x=1; x<=num_rods; x++)
triangles = triangles + get_tri(amt);
prob = tri_prob(num_rods, triangles, prob);
cout << "The probability that "<< num_rods << " rods will form triangles is:" <<
endl;
cout << prob <<"%"<< endl;
} while (num_rods!= SENTINEL);
|
You never reset the triangles variable. That means if you decided to find the number multiple times, the triangle count from previous attempts is carried over.
You should also be putting the
cin >> num_rods
at the bottom of the loop. Otherwise, you're going to run through the code after you enter your sentinel value.
1 2 3 4 5 6 7 8 9 10 11
|
int get_tri(int& amt)
{
for(x=0; x<200; x++)
{
//stuff
if (something...)
return amt;
else
return 0;
}
}
|
What is the purpose of this loop? You have return statements in there. When the function returns, the loop would be terminated. You're never going to loop.
1 2 3 4 5 6 7 8 9 10 11 12
|
if (break1>break2)
{
side1 = break1; //determines side 1
side2 = break1 - break2; //determines side 2
side3 = 1 - break2; //determines side 3
}
else
{
side1 = break2;
side2 = break2 - break1;
side3 = 1 - break2;
}
|
Think about the values you're setting. The largest value should actually be the length of two sides, right???
1 2 3 4 5 6
|
float tri_prob(int num_rods, int triangles, float& prob)
{
prob = (triangles/num_rods)*100;
return prob;
}
|
Triangles and num_rods are both integers. That means the quotient is going to be an integer. Since triangles/num_rods is (probably) going to be less than 1, that becomes 0. And 0 * 100 is still 0.