Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question 01 : The longitude of a geographic location can be expressed in one the

ID: 3672732 • Letter: Q

Question

Question 01: The longitude of a geographic location can be expressed in one the following three formats:(c language)

Decimal degrees. Example:     50.15395

Degrees, minutes, and seconds. Example: 50    9     14.220000

Degrees and minutes. Example: 50      9.237000

Write a single function C program that displays the following menu:

Decimal degree input

Degrees, minutes, and seconds input

Degrees and Minutes input

It then prompts the user to select his input choice and reads that choice. If the choice is invalid your program must display an appropriate error message and terminate; otherwise it reads the input. If the input is invalid your program must display an appropriate error message and terminate; otherwise it converts the input to each of the other two longitude formats and then displays each one of these formats.

: Your program must be general and it must behave as in the sample program runs below:

:

A longitude can have values from 0 degrees to 180 degrees inclusive, i.e., 0 degrees 180

1 degree = 60 minutes, 1 minute = 60 seconds.

A minute can have values in the interval [0 . . . 60), i.e., 0 minutes < 60

A second can have values in the interval [0 . . . 60), i.e., 0 seconds < 60

Explanation / Answer

Please find the partial code below, hopes it will help :

#include <stdio.h>


void printMenu(){
printf("Enter an option");
printf("1. Decimal degree input");
printf("2. Degrees, minutes, and seconds input");
printf("3. Degrees and Minutes input");
}

int main(void)
{
int option;

printMenu();
scanf("%d",&option);

if(option == 1){

float dec;
printf("Please input the value: ");
scanf("%f", &dec);
  
int deg = (int)dec;
// int min = (int)round(fabs(dec - trunc(dec)) * 1e4);
float min = (dec - deg) * 60;

int minAlone = (int)min;
  
float sec = (min - minAlone) *60;
int secAlone = (int)sec;

printf("Degrees, minutes, and seconds : = %d %d %d",deg,minAlone,sec);
printf("Degrees and minutes = %d %f",deg,min);


}else if(option == 2) {

char *in;
printf("Please input the value: ");
scanf("%s", &in);
  

}

return 0;
}