I am a Java developer and I’m just starting to teach myself c++ as well. I know some of the differences between Java and c++ but I’m not sure what is going on here. Here is the code I am having a problem with. Its just from a tutorial so I’m not worried about accuracy.
void calculateHourly() {
float totalWeeklyWage = mFltHourlySalary * mIntHoursWorked;
float totalSales = mIntCostOfShoe * mIntUnitsSold;
float totalCommission = (mIntHourlyCommission / 100) * totalSales;
float grandTotalWage = totalWeeklyWage + totalCommission;
cout << "You will get $" << grandTotalWage << " for selling " << mIntUnitsSold << " shoes in a week."
<< endl;
}
The problem is the line
float totalCommission = (mIntHourlyCommission / 100) * totalSales;
For whatever reason totalCommission = 0 when this method is done running. I have debugged this and all the other variables in this method equal what they are supposed to be equal to. With my Java cap on and the little knowledge I have of c++ tell me this should be working.
Am I missing something painfully simple in this method or is there a greater issue at hand? Any and all help is greatly appreciated.
The following uses integer division, the result of which is also integer:
Either cast
mIntHourlyCommissiontofloat, or turn100into afloatliteral:100.0f.