Thread: Looping and I/O Stream

  1. #1

    Looping and I/O Stream

    I need to write a program where the system calculates the average of ten floating point numbers and calculates the standard deviation. The user is to input ten numbers and he program is supposed to display the average and standard deviation. I was using a FOR Loop for the input of the numbers but am confused as to where I will do the calculation for standard deviation? Would I need to call a function for this? Can I store the values of each number and use an array to display them?

  2. #2
    Join Date
    Aug 2001
    mming, Game DevelopmentCSR >&<>&2Minimization of boolean functions, PROM,PLA design >&0>&WA, USA guitar, dogsCommercial Aviation >&>>&USAProgramming
    Average is a laymans term and it does not make any sense when used in the same sentance as standard deviation. Is average supposed to be the arithmetic mean, the midrange, midpoint, mode, or median? Yes you have to store the input into variables. Also you will have to use some math functions to aid the standard deviation calculation, and yes the calcuation would be done in a function.
    I compile code with:
    Visual Studio.NET beta2

  3. #3

    Looping and I/O stream

    The program I am to write is to find the average of ten numbers.
    Also Show what the standard deviation is. The formula given is as follows:
    Standard Deviation=sqrt(sum of squared values/10)

    Sum of the squared values deviation is:

    pow ((value1- average),2) + pow((value2-avg),2).......

    Do I have to do int v1, v2, v3 ...... Until ten?
    I tried it this way:

    # define max 10
    int count
    for(count=0; count<max; count++)
    cout<<"enter a number ";

    Should I put a function after cin to hold the values of the numbers?

  4. #4
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    I am pretty sure average always implies mean.

    Use an array to do this.

    const int NUM_ELEMENTS = 10;

    //main, includes, etc

    int count=0;
    int numbers[NUM_ELEMENTS];
    while (count < NUM_ELEMENTS]) {
    cin >> numbers[count];

    // use another loop to calculate average

    // use yet another loop to calculate the standard deviation after the average is known
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Raw I/O vs. Stream I/O
    By NuNn in forum C Programming
    Replies: 1
    Last Post: 03-17-2009, 08:32 AM
  2. Stream I/O
    By NuNn in forum C Programming
    Replies: 7
    Last Post: 02-23-2009, 02:33 PM
  3. Overlapped I/O and Completion Port :: Winsock
    By kuphryn in forum Windows Programming
    Replies: 0
    Last Post: 10-30-2002, 05:14 PM
  4. File Stream I/O
    By pldd4 in forum C++ Programming
    Replies: 2
    Last Post: 10-03-2002, 08:15 AM
  5. i/o stream
    By lupi in forum C++ Programming
    Replies: 1
    Last Post: 09-09-2001, 12:55 AM