loops and I/O file.

This is a discussion on loops and I/O file. within the C++ Programming forums, part of the General Programming Boards category; I am stuck trying to write a program. The program is supposed to do the following things: 1. accept 10 ...

  1. #1
    Unregistered
    Guest

    Question loops and I/O file.

    I am stuck trying to write a program.
    The program is supposed to do the following things:
    1. accept 10 floating point numbers from a user,add all and divide by ten to get the average.
    2. use two formulas to calculate a standard deviation.
    3. display the results and any numbers that were input which are not four standard deviations away from the average should be dropped and a new average and deviation calculated.

    I know we are to use looping methods for the formula. I started with a loop to calculate the average. So I thought within that loop I would call a function to execute the deviation formula (number - average squared) but that wouldn't work because the average has not been calculted yet. My question is where can I store these numbers? Also, can I execute this formula wherever I store them?
    One more thing, when writing number-average squared, is the syntax as follows:
    pow((number-average),2)

  2. #2
    Registered User matheo917's Avatar
    Join Date
    Sep 2001
    Posts
    279

    Red face

    you need to post some code and point out your problems then...

    nobody here will do your homework for you....

    show us some effort and you shall receive help...

  3. #3
    Registered User matheo917's Avatar
    Join Date
    Sep 2001
    Posts
    279

    Thumbs up

    ok i just need you to tell me how far ahead are you in your class, have you covered classes and pointers???... and it would really help if you post code that you were working on, so i could follow your idea and coding form...

    Regards,
    matheo917

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    155
    declare array of 10 floats.
    declare a float to act as a running total and initialize to zero.
    declare a float to act as the standard deviation.
    declare an int to act as the number of floats used to calculate the average and assign it the value of 10.
    declare an array of ten floats to hold each deviation.
    declare an char to act as a flag and assign it the value of F.

    use a loop to get user input for ten floats assigning each one to a successive element of the array.

    use a while loop to run all of the calculations. use the flag equal to F as the conditional

    use a loop to add each element of the array to the running total.

    divide the running total by number of floats used to calculate the average. Assign the value to average.

    use a loop to calculate the deviation for each element of the original array.

    reset the running total to zero.

    use a loop to add each deviation to running total.

    divide running total by the number of elements in the array to get the standard deviation.

    set the flag to T.

    use a loop to compare each deviation from the original standard deviation. If any of the original float inputs are greater four times the standard deviation remove them from the array by shifting all elements of the original input array to the left by one and decrease the int by one and change the flag to value F.


    if the flag is F reset the running total to zero and recalculate a new standard deviation using the new input array, etc. Repeat the process until all values in the array are less than four standard deviations from the mean.

    once the control loop stops running (because the flag remains T) display the average, standard deviation, and whatever other information you wish/need to display.

    If you allow use of negative numbers then there are a few more twists to the plot but if you know how to do it by hand and if you can follow the plot to here I suspect you can make the necessary allowances (there is a function to return the absolute value of a number if you wish to use that approach).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with a code using File I/O and Loops
    By bns1201 in forum C Programming
    Replies: 27
    Last Post: 10-17-2008, 10:19 PM
  2. Subtle(?) File I/O Problem
    By cecomp64 in forum C Programming
    Replies: 9
    Last Post: 07-16-2008, 12:39 PM
  3. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 08:51 PM
  4. File I/O Question
    By Achy in forum C Programming
    Replies: 2
    Last Post: 11-18-2005, 12:09 AM
  5. File I/O problems!!! Help!!!
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 05-17-2002, 09:09 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21