Edited

...
Last edited on
First of all, since your weather variable is an int, when it asks you for the weather, you have to enter an integer.
If that's not what you want, #include <string> and change int weather; to string weather;.

Now, your problem is that in golf::calculate(), you declare three int variables (sunny, raining, and overcast) that, since they are all uninitialized, all contain some random garbage values.
Then you try to compare your weather variable with those values.
Unless the user is really good at guessing what values to enter for it to be sunny, raining, or overcast, it's never going to be any of them.

So, if you change weather to a string like I suggested, you just have to do
1
2
3
4
5
if (weather == "sunny")
    // etc.
else if (weather == "overcast")
    // etc.
// and so on 
and you don't need those other variables at the beginning.
Remember the difference between = and ==?
...
Last edited on
I suspect a rounding problem here.
Probably, what's happening is that members * .12 is giving you something like 11.9999999999999 (remember, floating-point numbers are inexact, so it can't represent every number exactly) and that gets casted to an int by dropping everything after the decimal point (leaving you with 11).

You could try messing with the rounding functions in <cmath> (see http://www.cplusplus.com/reference/cmath/ for a list), or you could just convert your decimals into fractions and do something like
1
2
3
4
5
6
7
8
9
10
11
12
if (weather == "sunny")
{
    members = members / 4; // members * 0.25
}
else if (weather == "overcast")
{
    members = (members * 3) / 25; // members * 0.12
}
else if (weather == "raining")
{
    members = (members * 3) / 100; // members * 0.03
}

For the second problem, you have else if (temp < 32) rather than just if (temp < 32), so that will never get checked unless the weather isn't sunny, overcast, or raining.
Thanks for your help! Everything works good now.
Topic archived. No new replies allowed.