Function doesn't work properly [SOLVED]

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.

Can anyone help?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <cstdlib>

using namespace 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;
}
Last edited on
Not with variables y and z as integers you won't.
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.
i didnt realise them being integers meant that you couldnt make a float using them...

its meant to be 24 anyway, its just the code needs to run 23 times...

It all works now though, thanks :)
Topic archived. No new replies allowed.