I have a program (below), and I know the function doesnt work, as 365 should return 24...
INTENDED IDEA:
y decreases by one every time, then divided by z. This is then multiplied to x, to make the slow decrease to 0.5, where it stops.
Counter increases each time, to count the number of executions.
#include <iostream>
#include <cstdlib>
usingnamespace std;
int bot,top;
int mult(float x, int y, int z, int counter);
int main()
{
cout << "Please enter the number of possibilities to check:\n\n";
cin >> bot;
cin.ignore();
top = bot;
cout << "\nWorking...\n" << "you would need " << mult(1,top,bot,1) << "objects to make it likely they share the property,\nof which there are " << bot << " possibilities.\n\nPress [Enter] to exit...";
cin.get();
}
int mult(float x, int y, int z, int counter)
{
do
{
counter += 1;
x = (x*(y/z));
y -= 1;
}
while (x > 0.5);
return counter;
}
And with top = bot = 365, counter will be 24 not 23.
because you start the counter with 1
Anyway you don't need to pass a counter variable to the mult function (as you are just passing a copy anyway) - just create a local variable in the mult function.