Thread: Need help with this Assignment

  1. #1
    Registered User
    Join Date
    Feb 2016
    Posts
    4

    Exclamation Need help with this Assignment

    I've this complicated assignment as I see it and I need HELP with it
    Question 01: The longitude of a geographic location can be expressed in one the following three formats:

    • 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:

    1. Decimal degree input
    2. Degrees, minutes, and seconds input
    3. 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

    Need help with this Assignment-hhhh-png

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Quote Originally Posted by Abdullah Mj View Post
    I've this complicated assignment as I see it and I need HELP with it
    Sure. What exactly do you need help with? Post what you've done so far (using code tags), and tell us where you're stuck.

    Quote Originally Posted by Abdullah Mj View Post
    Write a single function C program that displays the following menu:
    If you're supposed to write this in C, why did you post in the C++ forum?

  3. #3
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Quote Originally Posted by Abdullah Mj View Post
    I've this complicated assignment as I see it and I need HELP with it
    Question 01: The longitude of a geographic location can be expressed in one the following three formats:

    • 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:

    1. Decimal degree input
    2. Degrees, minutes, and seconds input
    3. 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
    Sure! Break this assignment up into chunks and do one thing at a time.

    You need to make a basic user interface and get that up and running. This can be easily tucked away inside of its own function. If you know printf(), you've already got a good part of the UI done. Next up is the use of scanf() or something to similar effect to read in user input. Write separate validation functions that return something simple, like booleans. Wait, does C have booleans? Anyway...

    But yeah, the basic structure of your program is, print some stuff, wait for user input, parse it, validate it and then do stuff after that.

  4. #4
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Actually, you wouldn't want to waste time writing separate functions when the assignment wants a single function C program. Basically everything has to be done in main().

    I think it would be more helpful to explain the mathematics. A good strategy is to put everything in degrees, because you can then derive the other answers.
    1 degree = 60 minutes, 1 minute = 60 seconds.
    In other words, 1 second is 1/3600 of a degree, 1 minute is 1/60 a degree. The output is such because the numbers after a point contain the other parts that you don't use. Take the example: 50.15395 degrees is 50 degrees and 9.237 minutes; or 50 degrees, 9 minutes, 14.22 seconds.

  5. #5
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Quote Originally Posted by whiteflags View Post
    Actually, you wouldn't want to waste time writing separate functions when the assignment wants a single function C program. Basically everything has to be done in main().
    That is 100% the wrong way to teach programming though. Write small composable functions that are easy to test in isolation. Overwhelming main with code does little in the way of teaching program structure and a means for testing.
    Last edited by MutantJohn; 02-16-2016 at 10:42 PM.

  6. #6
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    I'm not endorsing it, but it is a simple fact that the assignment instructions want a program consisting of main().

  7. #7
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    *throws arms in the air*

  8. #8
    Registered User
    Join Date
    Feb 2016
    Posts
    4
    Guys I've reached up to this and I don't know if what I did is right or not, also I've stucked I don't know how to proceed with it !?
    Code:
    #include <stdio.h>
    #include <math.h>
    int main(void) {
        int x;
        double y;
        printf("Choose the input method\n");
        printf("1.Decimal degrees\n");
        printf("2.Degrees, minutes and second\n");
        printf("3.Degrees and minutes\n");
        printf("\n");
        
        scanf("%d",&x);
        printf("\n");
    
        if (x==1){
            printf("Enter Decimal degrees");
            printf("\n");
            scanf("%lf",y);
            DMS = 
    
            
        }
        else if (x==2){
            printf("Enter Degrees, minutes and second");
            printf("\n");
    
        }
        else if (x==3){
            printf("Enter Degrees and minutes");
            printf("\n");
    
        }
        else {
            printf("The input does not exist");
        }
        scanf("%lf",&y);
        printf("\n");
    Last edited by Abdullah Mj; 02-17-2016 at 01:27 AM.

  9. #9
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    I would make sure that the menu options and text like "Enter decimal degrees:" match down to the capital letters.

    Additionally, you need to check the input as the assignment suggests. There is a range of inputs that are acceptable for degrees, minutes, and seconds. Like you were shown on the paper, there has to be an error output in those cases where the number is too big or small.

    Also where is the attempt to calculate everything?

  10. #10
    Registered User
    Join Date
    Feb 2016
    Posts
    4
    sorry guys but I didn't get any thing can u show me more briefly explanation ?!

  11. #11
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    In other words, 1 second is 1/3600 of a degree, 1 minute is 1/60 a degree. The output is such because the numbers after a point contain the other parts that you don't use. Take the example: 50.15395 degrees is 50 degrees and 9.237 minutes; or 50 degrees, 9 minutes, 14.22 seconds.
    This basically means that depending on the input that you have, you can break it down into minutes (and seconds), or add smaller parts together to get the answer.

    Say for example I had the input 50 degrees, 9 minutes, and 14.22 seconds. I know that there should be a way to add all this up into one big number. (I was able to explain in the quoted portion why it was all the same quantity.) I also know the ratios of everything in terms of degrees. (Also in the quote.)

    So if I add my input together:
    deg = deg + min/60 + sec/3600;
    I get the big 50.15395 answer stored in deg.

    From here, I can use deg to get other answer formats. This whole thing is one big math problem. Just try it.

  12. #12
    Registered User
    Join Date
    Feb 2016
    Posts
    4
    OK for now. But the real problem how can I write a command that reads the value after choosing the input method and shows the tow other units more over how can I define the condition of the numbers <= , >=, != and so on.

    I'm a really beginner in this world so be patience on me!

  13. #13
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    But the real problem how can I write a command that reads the value after choosing the input method and shows the tow other units
    You should use scanf to read in the other numbers. The scanf function can read more than one number at a time, it is just a matter of adding more %-conversion specifiers to the first string and adding more &-variables to the argument list. If you don't know how to read in floating point values you should review this part in your course materials.

    Note that you are free to call scanf() basically where you want to. Be sure to read your C file from the top down, and determine the ideal place to input numbers.

    shows the tow other units more over how can I define the condition of the numbers <= , >=, != and so on.
    You apparently know the basics of if-else, so I will be brief. It is a matter of expressing what you want to be true in order for the code underneath to execute... just like in math if you say deg > 60 that is either true or false. In programming though, we can also say if we want two or more things to be true at once with logical AND (&&), or for one thing to be true with logical OR (||).

    I'm a really beginner in this world so be patience on me!
    Please understand that to us the more you do yourself, the more that you can learn.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help me with my ASSIGNMENT
    By khelly in forum C++ Programming
    Replies: 1
    Last Post: 12-01-2011, 07:22 AM
  2. i seriously need help for my assignment :(
    By tianwu in forum C Programming
    Replies: 14
    Last Post: 11-26-2011, 01:34 PM
  3. Need help for my assignment .
    By kaizan777 in forum C Programming
    Replies: 2
    Last Post: 11-21-2011, 07:15 PM
  4. Replies: 3
    Last Post: 04-26-2009, 08:54 AM
  5. Assignment Help...maybe..
    By TerribleatC in forum C Programming
    Replies: 5
    Last Post: 01-05-2007, 08:05 AM