having trouble passing boolean values

  boolean, c++, return-value

I’m pretty new to C++ and I’m doing work for a school lab. I’m having trouble getting a boolean value to pass from the following function to a variable in the main function.

// define function IsBetterThanChance
int isBetterthanChance(double accuracy)
{
    if (accuracy > .50)
    {
        return true;
    }
    else
    {
        return false;
    }
}

And then these are the lines of code in the main that are relevant:

twopntDisplay = isBetterthanChance(twopntAccuracy);

    threepntDisplay = isBetterthanChance(threepntAccuracy);

    if (twopntAccuracy)
    {
        cout << "This player made 50% or above for his 2 point shots." << endl;
    }
    else
    {
        cout << "This player did not make 50% or above on thier 2 point shots." << endl;
    }

    if (threepntAccuracy)
    {
        cout << "This player made 50% or above for his 3 point shots." << endl;
    }
    else
    {
        cout << "This player did not make 50% or above on their 3 point shots." << endl;
    }

The problem I am running into is that the value returned is always true. Any suggestions on how to clean this up would be greatly appreciated.

Source: Windows Questions C++

LEAVE A COMMENT