M
M
Maxim Trofimov2018-02-15 21:36:28
iOS
Maxim Trofimov, 2018-02-15 21:36:28

How to count numbers using %?

language Swift 3 +
I want to count numbers using % . for example: 50 + 10%, or 200 - 25%
How to write these examples? if the % sign means at the moment the remainder of the division.
I ask for help

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Trofimov, 2018-02-15
@nuSan

In general, the solution is: 2 options
1st
More simple using the example 50+10%
1)50/10=5 // find out how much it is 10% of 50 (which in this example are 100%)
2)50+5=55 / / here is the answer 50+10%=55
2nd more tricky
postfix operator %
postfix func % (percentage: Int) -> Double {
return (Double(percentage) / 100)
}
var r = 50%10 //find out the percentage
PS Thank you trolls for what you are, without you progress would stop and pushes would be clean.

E
Eric Grizzzzlie, 2018-02-15
@Grizzzzlie

and 10% of what? You add 50 to a number that the program doesn't understand. You can do the following:
store 50+100 in num (variable), and then from this num%20 => find the percentage of this number.
If, of course, I understood you correctly,
but adding 50 + 20% is not even in mathematics

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question