Possible Duplicate:
C++ int float problem
I’m simply trying to calculate and print a percentage, and although the variables being used in calculation are displaying correctly, the final percentage keeps showing as “0”. Here is the code:
int iWageredTot = iBet * 4 * iGames;
cout<<"Total Won: "<<iBankRoll<<endl;
cout<<"Wagered total: "<<iWageredTot<<endl;
float iPercent;
iPercent = iBankRoll / iWageredTot;
cout<<iPercent<<"% edge\n"<<endl;
And this is the output:
Total won: -770
Wagered Total: 4000
0% edge
I tried using int, float, and double. What am I missing? Thank you for any help.
Maybe
If
iBankRollandiWageredTotare declared asint,iBankRoll / iWageredTotwill also be anintwhich will be then converted tofloat, but if it’s initially0, you’ll end up with afloat0.