What I would do is start with this:
Code:
#include <stdio.h>
double getType(void);
double getDiameter(void);
double getAltitude(void);
double getVelocity(void);
double getPerformance(void);
double getGenerator(void);
double getGearbox(void);
double density(double altitude);
int main(void)
{
printf("-- Wind turbine power calculator -- \n");
double A, V, Cp, Ng, Nb, p, Pwr, d, a, h;
A = getType();
d = getDiameter();
a = getAltitude();
V = getVelocity();
Cp = getPerformance();
Ng = getGenerator();
Nb = getGearbox();
p = density(a);
printf("density =%lf \n", p);
Pwr = p * Cp * 0.5 * Ng * Nb * V * V * V;
printf("Power =%0.3lf \n", Pwr);
return 0;
}
double getType(void)
{
return 0.0;
}
double getDiameter(void)
{
return 0.0;
}
double getAltitude(void)
{
return 0.0;
}
double getVelocity(void)
{
return 0.0;
}
double getPerformance(void)
{
return 0.0;
}
double getGenerator(void)
{
return 0.0;
}
double getGearbox(void)
{
return 0.0;
}
double density(double altitude)
{
return 0.0;
}
Change all the return 0.0 to return your test values. Then, compile and run the program and see if you get your expected result. If you don't, then perhaps the problem lies with your equation, whether the one in your program, or the one you computed for the expected value.
If you do get your expected result, you could change some other return values to keep checking that it wasn't a fluke. Once you're satisfied, implement getType. Test again. If getType works as expected, chose one (and only one) other function to implement, implement it then test. Keep on going until you have implemented all the functions. Done!
This systematic and incremental approach to development allows you to spot bugs early and hence more easily. What you did instead was to try and implement everything at once, then test. If there's a bug... well, you can still find it, but you'll need to do a lot more work with a debugger since it is more difficult to see where the bug might be.
EDIT:
Another thing. Do not use recursion like this:
Code:
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();
}
return a;
}
Rather, use iteration:
Code:
double getAltitude(void)
{
double altitude;
for (;;)
{
printf("\nEnter altitude (m):");
if (scanf("%lf", &altitude) == 1 && altitude <= 9000 && altitude >= 0)
{
break;
}
else
{
printf("Invalid input! Altitude must be between 0 and 9000m");
int c;
while ((c = getchar()) != '\n' && c != EOF);
}
}
return altitude;
}