0
Percentage of a variable
In c++, how do I turn a number that's in a variable into a percentage, as I don't know the number in advance, it depends on the users input. For example: 15 is in the variable, so I want 15% of 50. I've tried 'price = 50 - (perc)%;' & 'price = 50 - (perc%);', but nothing works. Thanks in advance.
3 Antworten
0
15% means 15/100*number,
so it should be 50-(50*15/100)
0
in code languages % operator is not the percent (it's almost the modulo, ie: to get the remainder of integer division)...
percentages needs to be "manually" computed:
price = price - price*perc/100;
// or: price*(1-perc/100)
0
Of course, I should have known that. Thanks guys!