Is the tank standing upright? Or on its side?
Check your variable types. What is "sa" supposed to be ?
Post all the code, using code tags ("</>" button).
#define h 8
long duration, distance, volume, n, duration_empty,percent_empty,sa,h;
h = height ;
8 = height ;
The tank is upright.
volume = height * crossSectionArea;
3.14 * radius * radius is a good way of expressing the cross section area constant. It makes it obvious how it's calculated rather than just putting a bare number in.
I am using a HC-204 ultrasound sensor to get distance and with that, I am trying to find the height of water that can be filled in the tank.