Simple Typecast Q (int to float)
Is there a better way to do this...?? (the 'wins' and 'losses' variables have been previously declared as 'int')
Code:
float blackjack::win_percentage()
{
//Prevents 'division by zero' errors
if ((wins + losses) == 0)
return 0.00;
else
{
//Cast 'wins' & 'losses' to float
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(1);
float answer = (( (float)wins / ( (float)wins + (float)losses)) * 100);
return answer;
}
}
I think there is a better way to perform this typecast.. also i think there is a different way to set precision.
Thanks in advance. :)