Code generating wrong answer
hi i have made this code to calculate the density when a user input for altitude is given using two different functions.
Code:
#include <stdio.h>
#include <math.h>
#define pi 3.14
double getAltitude();
double density(double a);
int main()
{
double p, a;
getAltitude();
p = density(a);
printf("density =%lf \n", p);
return 0;
}
double getAltitude()
{
double a;
double x;
printf("\nEnter altitude (m):");
scanf("%lf", &a);
if (a > 9000)
{
printf("Invalid input! Altitude must be between 0 and 9000m");
return getAltitude();
}
else if ( a < 0 )
{
printf("Invalid input! Altitude must be between 0 and 9000m");
return getAltitude();
}
x = density(a);
return a;
}
double density(double a)
{
double density, d ;
density = (1.2 - (1.33*pow(10, -4))*a);
return density;
}
however when the density is calculated it is always the wrong answer, for example if the user inputs an altitude of 1500 the density should then read 1.005 (using a calculator can easily be calculated), however i am getting a output of 1.2000.
where am i going wrong and what needs to be fixed?
cheers