How to stop the slip IF in C#?

There is such code
if (value > 0.5 && value < 0.75);
 value = value + onePercent * 150;

 if (value > 0.75 && value < 1);
 value = value + onePercent * 125;

 if (value > 1 && value < 2);
 value = value + onePercent * 100;


The essence of what the value (number) for all IFам slips, and each transaction is multiplied.
Ie, the number of turns in 3.05 25.19.

How to stop the multiplying after the first function?
Thank you.
March 19th 20 at 09:13
2 answers
March 19th 20 at 09:15
Solution
instead of the second and third if use else if
if () {
} else if () {
}
+ - Ashlynn commented on March 19th 20 at 09:18
March 19th 20 at 09:17
No, no, no, not so:
if (value > 0.75 && value < 1);
 value = value + onePercent * 125;

Here's how:
if (value > 0.75 && value <= 1) {
 value = value + onePercent * 125;
}

or, at worst, this:
if (value > 0.75 && value <= 1) 
 value = value + onePercent * 125;

Look, you have a semicolon after the condition, it means that the conditional operator is now finished, and the next line will be executed always.
Write the terms so that they cover the entire range, i.e. if you have one if you have the condition x < 1.0, the next must be x >= 1.0 or Vice versa, and it is better to use if... else...
thank you - Ashlynn commented on March 19th 20 at 09:20

Find more questions by tags C#