- #1
jam12
- 38
- 0
Hello, i want to write a function in the form of "float estM( Planet *body);" to calculate radius^3/period^2 for the planet earth, where i have an array of values for radius and period of different planets.
Here is the program so far, i am getting a -NaN error:
#include <stdio.h>
#include <math.h>
typedef struct pt {
char *name;
float period; /* orbital period in years */
float radius; /* orbital radius in ast units */
} Planet;
main() {
float estM( Planet *body); /* Have been told that the function is of this form to calculate radius^3/period^2 for earth*/
Planet Earth;
Planet plist[6];
int n, i;
Planet *body;
body=&Earth;
char nameMe[]="Mercury", nameV[]="Venus", nameE[]="Earth", nameMa[]="Mars", nameJ[]="Jupiter", nameS[]="Saturn";
plist[0].name = nameMe;
plist[0].period = 0.241;
plist[0].radius = 0.387;
plist[1].name = nameV;
plist[1].period = 0.615;
plist[1].radius = 0.723;
plist[2].name = nameE; /*Here is info for Earth */
plist[2].period = 1.0;
plist[2].radius = 1.0;
plist[3].name = nameMa;
plist[3].period = 1.881;
plist[3].radius = 1.524;
plist[4].name = nameJ;
plist[4].period = 11.86;
plist[4].radius = 5.203;
plist[5].name = nameS;
plist[5].period = 29.46;
plist[5].radius = 9.540;
n=6;
printf("Planet name\t period\t radius\n");
for (i=0;i<n;i++) {
printf("%s\t\t %.3f\t %.3f\n",plist.name, plist.period, plist.radius);
}
printf("%f\n",estM(body)); /* I want to calculate radius^3/period^2 for Earth */
}
float estM( Planet *body) { /*function to caculate radius^3/period^2 for Earth */
float m;
Planet Earth;
body=&Earth;
m=pow((*body).radius,3)/pow((*body).period,2);
return m;
}
Here is the program so far, i am getting a -NaN error:
#include <stdio.h>
#include <math.h>
typedef struct pt {
char *name;
float period; /* orbital period in years */
float radius; /* orbital radius in ast units */
} Planet;
main() {
float estM( Planet *body); /* Have been told that the function is of this form to calculate radius^3/period^2 for earth*/
Planet Earth;
Planet plist[6];
int n, i;
Planet *body;
body=&Earth;
char nameMe[]="Mercury", nameV[]="Venus", nameE[]="Earth", nameMa[]="Mars", nameJ[]="Jupiter", nameS[]="Saturn";
plist[0].name = nameMe;
plist[0].period = 0.241;
plist[0].radius = 0.387;
plist[1].name = nameV;
plist[1].period = 0.615;
plist[1].radius = 0.723;
plist[2].name = nameE; /*Here is info for Earth */
plist[2].period = 1.0;
plist[2].radius = 1.0;
plist[3].name = nameMa;
plist[3].period = 1.881;
plist[3].radius = 1.524;
plist[4].name = nameJ;
plist[4].period = 11.86;
plist[4].radius = 5.203;
plist[5].name = nameS;
plist[5].period = 29.46;
plist[5].radius = 9.540;
n=6;
printf("Planet name\t period\t radius\n");
for (i=0;i<n;i++) {
printf("%s\t\t %.3f\t %.3f\n",plist.name, plist.period, plist.radius);
}
printf("%f\n",estM(body)); /* I want to calculate radius^3/period^2 for Earth */
}
float estM( Planet *body) { /*function to caculate radius^3/period^2 for Earth */
float m;
Planet Earth;
body=&Earth;
m=pow((*body).radius,3)/pow((*body).period,2);
return m;
}