I am getting a -NaN message and I don't understand why?
The program so far compiles okay. But prints "the value of lat1 is -NaN."
Any help would be greatly appreciated.
# include<stdio.h>
# include<math.h>
float get_lat1();
int main (void)
{
float lat1;
get_lat1();
printf("the value of lat1 is %f \n", lat1);
return (0);
}
float get_lat1()
{
int degrees;
int minutes;
float seconds;
float lat1;
char direction;
printf("Enter the Prepare to enter data for first coordinate:\n");
printf("Enter the latitude in the form (DD MM SS.S):\n");
scanf("%d" ,°rees);
scanf("%d" ,&minutes);
scanf("%f" ,&seconds);
lat1 = degrees + (minutes / 60) + (seconds / 3600);
do
{
printf("Enter N for North or S for South: \n");
fflush(stdin);
scanf("%c", &direction);
if(direction == 83)
{
lat1 = -lat1;
return(lat1);
}
else if(direction == 78)
{
lat1 = lat1;
return(lat1);
}
else
{
printf("Invalid Input! Please Try Again!\n");
}
}while (direction != 83 || direction != 78);
printf("the value of lat1 is %f \n", lat1);
return(lat1);
}