Hey everyone. I'm new to C programming. I'm working on a little code of my own right now and it compiles fine, but after the user inserts some data and presses enter, this error pops up. Here's the code:
Code:
#include <stdio.h>
#include <math.h>
double G, T, Mtot, R, v, B, A, C, Pi, distance;
int main (void)
{
G = 6.67e-11;
Pi = 3.14159;
printf("Enter the combined mass of the systems (kg):");
scanf("%lf", &Mtot);
printf("Enter distance between galaxies (kpc):");
scanf("%lf", &R);
printf("Enter the relative velocity of the approaching galaxy (km/s):");
scanf("%lf", &v);
while (R>=0)
{
C = ((pow(v,2))/2.0) - (G*Mtot)/R;
T = (2.0*Pi*v*(pow(R,2)))/(C*G*Mtot);
printf("\nwhen T = %d years,",T);
printf(" then the other galaxy is %f kpc away",R);
R=R-0.05;
}
system("pause");
return(0);
}
Once you run it, the segmentation error comes up after the combined mass is entered (Mtot). Any help on fixing this problem would be appreciated.
Oh, and I've been using Cygwin, if that's of any consequence. It's the program we're given for the class I'm in.