Thread: i need help

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    6

    i need help

    hi everyone,

    this is my first post, i have just started c programing and having some difficulties. I hope someone can help me on this website.

    i am programing in c++, to be specific.

    i have to write a c program which calculates the area under a curve using the simson rule.

    simpson rule : Yn+1=Yn-1+1/3[Xn+1+4Xn+Xn-1]

    data points, sould be read from standard input using scanf(). when no more data is available from input then the area and some discription should be written to standard output using printf().

    Implementation:
    -a seperate function called simpson() must be written which calculates each new increment of area using three current data points
    -every secon data point must be used as a centre for evaluating the area using three data points( the centre point is Xn)
    -the main() only reads the input, accumalates the situation, keeps track of the cauurent values of x and y, and finally prints the results.


    i kind of no whats going onm im goin to use a y variable , 3 x variables, a total variable and a null character to exit the while loop.(does this sound about right?)

    im sorry for the long post just wanted to make sure i made sence, im getting some tutoring tomorow but i wanted some help on getting started first.

    thanks very much.any help is appritiated.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    Quote Originally Posted by efti
    i am programing in c++, to be specific.

    i have to write a c program which.....
    perhaps you should pick a language first
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    Quote Originally Posted by efti
    i kind of no whats going onm im goin to use a y variable , 3 x variables, a total variable and a null character to exit the while loop.(does this sound about right?)

    3 x variables? try 1.

    a null character to exit the while loop? try a condition which evaluates to 0
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  4. #4
    Registered User
    Join Date
    Apr 2005
    Posts
    6
    Im programing in ANSI C. ok ill try 1 x variable and a condition that evaluates to 0 to exit the loop. im still having trouble implementing the formula, im a very ameture programer. can anyone help me get it started?

  5. #5
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    well, X and Y are your points on a cartisan graph. n is the increment (i forget the mathematical term).



    i'm guessing youwill need something like this
    Code:
    //untested
    int X = current_data_point_x;
    int Y = current_data_point_y;
    
    float result = 0.0;
    
    for(int n = 0; n < 3; n++)
    {
        result = Yn-1+1/3(Xn+1+4Xn+Xn-1);
        //cout << result << endl; //c++
        printf("%f\n", result);   //c
    }
    Last edited by misplaced; 04-10-2005 at 02:32 AM.
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  6. #6
    Registered User
    Join Date
    Apr 2005
    Posts
    6
    thanks for your halp "misplaced"

    anyone else?

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Question reposted here without effort.
    http://cboard.cprogramming.com/showthread.php?t=64168
    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.

Popular pages Recent additions subscribe to a feed