Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation C programming Help

    Hey I'm having some trouble with arrays at the moment.
    The program I need help with needs to read a inputed a set of numbers (two in each set).
    Then with these numbers I need to find the difference of the second number compared to the first number.
    And the percentage of error it is off by. And this all needs to be done within a sentinel loop

    Can any of you help me?

    This is what i have came up with so far ill keep updating as i add onto it.


    //To take a set of number pairs where the first number is the actual number and the secound is the guess
    //With this find absolute error and relative error.
    //Absolute error is defined as E(abs)=W(guess)-W(real)
    //Relative error is E(real)=100*E(abs)/W(real) where the result is a percentage
    //Use a function with a sentinel loop to read the data
    //Write a function to calculate both Errors and display them in a table
    //Finally Compute and print the average of both the absolute errors and absolute values of relative erros



    #include <stdio.h>
    #include <string.h>

    void main(void)
    {
    double Cweight=0; //Variable to be used for the Correct weight
    double Gweight=0; //Variable to be used for the guessed weight
    double absolute;
    double relative;

    printf("\nPlease Input the Correct weight hit enter then input Guess weight\n");
    printf("\nTo quit press 0\n");
    do{ //Do while function

    scanf("%lg",Cweight);
    scanf("%lg",Gweight);

    absolute=Gweight-Cweight;
    relative=100*absolute/Cweight;

    printf("\n Absolute Error=%g Relative Error=%g\n",absolute,relative);

    }while(Cweight > 0);

    return 0;
    }
    Last edited by Jamie69; 12-01-2011 at 01:32 AM. Reason: Added my code

  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Well what have you got so far? Post your code.
    OracleGuy


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •