Code:

int main()
{
//-------------------------------------Identifying Variables------------------------------------------------------------//
float
pi,
phi,
theta,
theta_rad,
phi_rad,
air_speed,
wind_speed,
wind_correction_rad,
wind_correction,
heading_you_should_take,
variation,
distance,
total_time,
num_checkpoints,
next_checkpoint,
next_checkpoint_time,
ground_speed,
back_actual,
back_ground_speed,
back_wind_correction_A,
back_wind_correction_B,
back_theta,
back_theta_rad,
back_wind_correction_rad,
heading_you_should_take_back,
back_time,
num_checkpoints_back,
next_checkpoint_back,
next_checkpoint_time_back,
total_route_time_to_and_back,
total_distance_to_and_back,
new_theta,
new_phi,
new_wind_speed,
new_distance,
new_phi_rad,
new_theta_rad,
new_wind_correction_rad,
new_total_time,
new_wind_correction,
new_ground_speed,
new_heading_you_should_take,
new,
home;
int
i,
j,
new_location;
//---------------------------------------Initial Inputs-----------------------------------------------------------------//
printf("WELCOME TO SEAN'S E-7B! -its still a work in progress...\n\n");
while(true)
{
printf("\nEnter your desired course in degrees:--------------------> ");
scanf("%f" , & theta);
printf("Enter your desired air speed in knots:-------------------> ");
scanf("%f" , & air_speed);
printf("Enter wind angle in degrees:-----------------------------> ");
scanf("%f" , & phi);
printf("Enter wind speed in knots:-------------------------------> ");
scanf("%f" , & wind_speed);
printf("Enter the distance you will travel in nautical miles:----> ");
scanf("%f" , & distance);
printf("Enter the amount of magnetic variation:------------------> ");
scanf("%f" , & variation);
//---------------------------------------Defining Equations---------------------------------------------------------------//
pi=3.1416;
phi_rad = phi*(pi/180);
theta_rad = theta*(pi/180);
wind_correction_rad = asin( sin( phi_rad - theta_rad ) * (wind_speed / air_speed));
if (wind_correction_rad >0 && wind_correction_rad < (pi/2) )
{
wind_correction = wind_correction*1;
}
else
wind_correction = wind_correction*(-1);
wind_correction = wind_correction_rad*(180/pi);
ground_speed = sqrt( pow(air_speed,2) + pow(wind_speed,2) - (2*air_speed*wind_speed*cos(phi_rad - theta_rad - wind_correction_rad)));
heading_you_should_take = variation + theta + wind_correction;
total_time = (distance / ground_speed) *60;
//----------------------------------------Return Data----------------------------------------------------------------------//
printf("\n\nYour wind correction angle is: %.1f ", wind_correction);
printf("\nThe course you should take is: %.1f ", heading_you_should_take);
printf("\nYour ground speed is: %.1f", ground_speed);
printf("\nIt should take you about %.1f minutes to reach your final destination", total_time);
//---------------------------------------Loop to Get and Return Checkpoint Data--------------------------------------------//
printf("\n\n\nEnter the number of check points you will cross: " );
scanf("%f" , & num_checkpoints);
printf("\n");
for (i=0;
i< num_checkpoints;
i++)
{
printf("\nEnter nautical miles to next checkpoint: ");
scanf("%f" , & next_checkpoint);
next_checkpoint_time = (next_checkpoint / ground_speed) * 60;
printf("It will take you %.2f minutes to get to your next checkpoint.\n" , next_checkpoint_time);
}
//-------------------------------------------Return Home or New course?-----------------------------------------------------//
printf("\n\n\nPress 1 to return home, or 2 to go to new location: ");
scanf("%d", &new_location);
//------------going back equations--------//
if (theta > 180)
back_theta = theta - 180;
else
back_theta = theta + 180;
back_actual = back_theta - wind_correction + variation;
back_wind_correction_A = wind_correction * (-1);
phi_rad = phi*(pi/180);
back_theta_rad = back_theta*(pi/180);
back_wind_correction_rad = asin( sin( phi_rad - back_theta_rad ) * (wind_speed / air_speed));
if (back_wind_correction_rad >0 && back_wind_correction_rad < (pi/2) )
{
back_wind_correction_B = back_wind_correction_A*1;
}
else
back_wind_correction_B = back_wind_correction_A*(-1);
back_ground_speed = sqrt( pow(air_speed,2) + pow(wind_speed,2) - (2*air_speed*wind_speed*cos(phi_rad - back_theta_rad - back_wind_correction_rad)));
heading_you_should_take_back = variation + back_theta + back_wind_correction_B;
back_time = (distance/back_ground_speed) * 60;
total_route_time_to_and_back = total_time + back_time;
total_distance_to_and_back = 2 * distance;
//---GOING BACK CODE---//
if (new_location == 1)
//---inputs---//
{
printf("\n\nYour new wind correction angle is: %.1f", back_wind_correction_A);
printf("\nYour new course is: %.1f " , heading_you_should_take_back);
printf("\nYour new ground speed is: %.1f", back_ground_speed);
printf("\nIt should take about %.1f minutes to return.", back_time);
printf("\n\n\nEnter the number of check points you will cross: " );
scanf("%f" , & num_checkpoints_back);
printf("\n");
//---loop for checkpoint distances---//
for (j=0;
j< num_checkpoints_back;
j++)
{
printf("\nEnter nautical miles to next checkpoint: ");
scanf("%f" , & next_checkpoint_back);
next_checkpoint_time_back = (next_checkpoint_back / back_ground_speed) * 60;
printf("It will take you %.2f minutes to get to your next checkpoint.\n" , next_checkpoint_time_back);
}
//---total time and distance for whole trip---//
printf("\n\n\nYour total route should take about %.1f minutes.", total_route_time_to_and_back);
printf("\nTotal distance covered is about %.1f miles.", total_distance_to_and_back);
}
//---NEW LOCATION CODE---//
else if (new_location == 2)
{
printf("You chose a new location.");
printf("\n\nEnter the new TRUE heading from current location: ");
scanf("%f", new_theta);
printf("Enter wind angle in degrees:-----------------------------> ");
scanf("%f" , & new_phi);
printf("Enter wind speed in knots:-------------------------------> ");
scanf("%f" , & new_wind_speed);
printf("Enter the distance you will travel in nautical miles:----> ");
scanf("%f" , & new_distance);
//---equations for new location---//
new_phi_rad = new_phi*(pi/180);
new_theta_rad = new_theta*(pi/180);
new_wind_correction_rad = asin( sin( new_phi_rad - new_theta_rad ) * (new_wind_speed / air_speed));
if (new_wind_correction_rad >0 && new_wind_correction_rad < (pi/2) )
{
new_wind_correction = new_wind_correction*1;
}
else
new_wind_correction = new_wind_correction*(-1);
new_wind_correction = new_wind_correction_rad*(180/pi);
new_ground_speed = sqrt( pow(air_speed,2) + pow(new_wind_speed,2) - (2*air_speed*new_wind_speed*cos(new_phi_rad - new_theta_rad - new_wind_correction_rad)));
new_heading_you_should_take = variation + new_theta + new_wind_correction;
new_total_time = (new_distance / new_ground_speed) *60;
//-----outputs for new location---//
printf("\n\nYour wind correction angle is: %.1f ", new_wind_correction);
printf("\nThe course you should take is: %.1f ", new_heading_you_should_take);
printf("\nYour ground speed is: %.1f", new_ground_speed);
printf("\nIt should take you about %.1f minutes to reach your final destination", new_total_time);
}
else
return(0);
}
//-------------------------------------------End Program--------------------------------------------------------------------//
return(0);
}