Thread: C program for Class --- DUE TODAY!!! AHHHH

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    6

    C program for Class --- DUE TODAY!!! AHHHH

    well i need help, im an EE in a prog. and apps course.. and i dont know how to do this program at all...the teacher explains through writing...not through examples...so i cant learn..were not in a lab ever ... its all lecture, so im learning NOTHING! my friend has my C book so i cant look things up...if you could help id realy appreciate it...(if you feel like it you can write the program :P )


    this is the assignment...

    ****Write a C program which displays HUGE_VAL, and then executes one portable, non-trivial, in-bounds test for any ten of the functions from math.h.
    Portable means that it should work on any system and make no assumptions about the precision or format of floating point. Non-trivial means that it does not just check a simple case where an argument or return value is 0. In-bounds means that it does not use arguments which would cause EDOM or ERANGE errors, or +-Infnity or NaN results.

    For each test, the function name, arguments, and return value(s) must be displayed, together with an indication if the return value(s) are correct or wrong. At the end of the program, a count of the total number of wrong return values must be displayed.

    You should assume that 4*atan(1) and exp(1) are accurate values for pi and e for use in checking results.

    Sample Output:

    HUGE_VAL = Infinity

    OK ceil(PI) = 4
    WRONG! cos(PI/3) = 0.500000000000000111 should be 0.5
    ...

    3 tests failed!
    ******

    So if you know what that means could you help me out a little?

    thanks in advance

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    http://www.catb.org/~esr/faqs/smart-....html#homework
    Now email that to yourself a week ago, when we could have made a reasonable effort to help you.

    We're not here to bail out people who leave homework to the last day, then hope for some miracle to appear on a message board.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    6
    ok...but that doesnt change the fact that im asking for help...im not asking for someone to write the program for me(yeah i did say jokingly that you could if you wanted to...~jokingly) but i still dont know what my teachers talking about.

    all i need is a simple push in the right direction...i just dont know what hes asking for

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    It sounds to me like they want you to write a C program which displays HUGE_VAL, and then executes one portable, non-trivial, in-bounds test for any ten of the functions from math.h

    Portable means that it should work on any system and make no assumptions about the precision or format of floating point. Non-trivial means that it does not just check a simple case where an argument or return value is 0. In-bounds means that it does not use arguments which would cause EDOM or ERANGE errors, or +-Infnity or NaN results.

    Also, it sounds like that for each test, the function name, arguments, and return value(s) must be displayed, together with an indication if the return value(s) are correct or wrong. At the end of the program, a count of the total number of wrong return values must be displayed.

    Furthermore, it looks like you should assume that 4*atan(1) and exp(1) are accurate values for pi and e for use in checking results.

    And then they gave you some Sample Output:

    HUGE_VAL = Infinity

    OK ceil(PI) = 4
    WRONG! cos(PI/3) = 0.500000000000000111 should be 0.5
    ...

    3 tests failed!

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Sep 2004
    Posts
    6
    wow, now it all makes sense..thanks

    yeah...not really, ... ive managed to write some code...

    printf("HUGE_VAL = %.20g\n\n", HUGE_VAL);
    pi = 2.1
    {

    if (x<10)
    {
    ??
    }
    else
    {

    jeez im confused...

  6. #6
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Code:
    #include <stdio.h>
    #include <math.h>
    
    int main(void)
    {
       double pi = 4.0 * atan(1.0), result = cos(pi / 3.0), answer = 0.5;
       if ( result != answer ) /* http://www.eskimo.com/~scs/C-faq/q14.5.html */
       {
          printf("WRONG! cos(PI/3) = %.18f should be %g\n", result, answer);
       }
       return 0;
    }
    
    /* my output
    WRONG! cos(PI/3) = 0.500000000000000111 should be 0.5
    */
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  7. #7
    Registered User
    Join Date
    Sep 2004
    Posts
    6
    thank you, that code helps clarify alot of things... after reading up on a lot of the things he was asking i figured out what he wants, so i shoud be alright for now....i just need 9 more math.h functions that sort of follow that code. i think i can handle it from here. thanksagain

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  2. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  3. I need some help with my program please.
    By agentxx04 in forum C Programming
    Replies: 9
    Last Post: 09-26-2004, 07:51 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM