# Thread: Simple O-ring calculator.

1. so I wanted to make a calculator that works out the size of a box needed before radius-ing the corners

so if I have an 85mm ID oring, and i want a corner radius of 10mm for example it will tell me that the box size is 70mm x 70mm.

so I've written a bit of code that works to the mm. but as I'm storing numbers in "int" I'm not able to get sub mm accuracy.

any idea on what I can use instead of int?

thanks

#include <stdio.h>
#include <conio.h>

int main(void)
{
int oringid;
int oringCir;
int cornerrad;
int cornerdie;
int cornerCir;
int val1;
int val2;
int boxSize;

int sides;

printf("enter O-ring ID");
scanf("%d", &oringid); //inputs value
printf("enter corner Radius");
scanf("%d", &cornerrad); //inputs value

//inner oring id converted to circumfrence
oringCir = oringid * 3.14159265359;
//corner radius is converted into diameter
cornerdie = cornerrad * 2;
//then converted in circumfrence
cornerCir = cornerdie * 3.14159265359;
//take away corner circumfrence from oring circumfrence
val1 = oringCir - cornerCir;
val2 = val1 / 4;
boxSize = val2 + cornerdie;

printf("with %d radius the box needed is: %d", cornerrad, boxSize );

getch();

}

2. Originally Posted by jcb121
any idea on what I can use instead of int?
Use 'float' - not the most memory efficient way to do it but that's not an issue here. Also you might find it helpful to include math.h.

Also since those are currently all ints, you might be introducing a big rounding error with pi.

3. Scale everything up so working in um, ie 1mm = 1000

4. the depth of an o-ring groove has to be spot on with quite tight tolerances, there are charts available for o-ring sizes.

5. Originally Posted by Jonathan
Also since those are currently all ints, you might be introducing a big rounding error with pi.
It will because of the implicit conversion of the result to int. So 11 * 3.14159 could be treated as

int(11.0 * 3.14159)=int(34.55)=34

or

11 * int(3.14159) = 33

Either is wrong...

depending on the compiler. .

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•