# Calculating a floating point, but not by if's & elseif's ?

This is a discussion on Calculating a floating point, but not by if's & elseif's ? within the C++ Programming forums, part of the General Programming Boards category; This is the code, first of all, all variables are floats and swingTolerance has a value of 40: Code: swing ...

1. ## Calculating a floating point, but not by if's & elseif's ?

This is the code, first of all, all variables are floats and swingTolerance has a value of 40:

Code:
```
swing = AngleSubtract( destination, *angle );
scale = fabs( swing );

if ( scale < swingTolerance * 0.01 ) {
scale = 0.01;
} else if ( scale < swingTolerance * 0.02 ) {
scale = 0.02;
} else if ( scale < swingTolerance * 0.03 ) {
scale = 0.03;
} else if ( scale < swingTolerance * 0.04 ) {
scale = 0.04;
} else if ( scale < swingTolerance * 0.05 ) {
scale = 0.05;

(else if's continue into higher numbers 1.20 ...1.21 ...1.22 ect)

} else {
scale = 0.1;
}```
AngleSubtract() is a function for finding difference between angles, and fabs() finds absolute value.

I'm fairly new to coding and wanted to know if there was a way to calculate the scale variable with floating point precision rather than this sequence of if's and elseif's (where the floating point precision is lost). Here is one attempt...

Code:
```	swing = AngleSubtract( destination, *angle );
scale = fabs( swing );

scale = swingTolerance *= .5 + scale;```
...where I tried to set up the code to find the scale value on its own with floating point precision for each step/code pass/cycle. This didn't work at all. The problem is that I'm new to programming and I don't know how to arrange the different variables so scale can be calculated with one line or statement, rather than through a series of if's and elseif's. I know there must some simple, logical way to get this working. The trick must have something to do with the code being able to read the scale variable before it is modified each step/code pass/cycle.

I can provide more information if necesary. This project uses no external libraries either, so I know the solution needs to be self contained in this code and can't rely on any premade functions from C#, .Net, or OS specific libraries. Any help would be greatly appreciated.

```swing = AngleSubtract( destination, *angle );