# Thread: I've A Question

1. Hey Guys,

I have a question here:

Write a program that reads a set of floating point values from user input and computes the count of values, the average and the standard deviation.

You can compute the quantity by keeping track of count, the sum and the sum of squares as you process the input values..

2.

3. That's asking to do your homework for you :P And you haven't stated what language you are using.

Use an array.

4. Originally Posted by pyoko
That's asking to do your homework for you :P And you haven't stated what language you are using.

Use an array.

yeah...=) i have try the question for hours.This is c++ language

5. Like pyoko said, use an array of floating point numbers as your main data structure. Then set up a loop, and read user input one by one into your array ( it is good practice to include some form of validation routine, to make sure you get only valid floats ), bearing in mind that you need some way to exit the loop, even if the user only enters nonsense. Once the array is populated you can then calculate the count, average and standard deviation; there are library routines for that I believe, or you can do that manually. The trick with C++ is to keep everything as simple and straightforward as possible - the simpler your routine, the less potential for errors you will have. And always assume that the user is a plonk, so your routine must be able to handle nonsense input.

6. thanks for your feedback.Can u take a look on my wrong answer

#include <iostream>
#include <cmath>
using namespace std;
int main ()
{
int sum=0;
int numbers;
int sumproduct=0;
int std;
int sumsqro;
int i=1;
while (i>=0)
{
cout<<"Enter A Number"<<endl;
cout<<"Press-1 to exit"<<endl;
cin>>numbers;

while (numbers!=1)
{

sum+=numbers;
sumproduct+=pow(numbers,2);
sumsqro=pow(sum,2);
}
i++;
}

std=sqrt((sumproduct-(sumsqro/i)) /i-1);

return 0;
}

7. You have not defined numbers as an array so it will only store one value. This could work if you read the values in within the loop. As it is you only read one value in before the loop starts. It might be better to use a do ... while loop.

You also have an error that means your loop will not terminate as you expect. I'll leave you to spot that...

 Bookmarks
##### Bookmarks
 Posting Permissions
 You may not post new threads You may not post replies You may not post attachments You may not edit your posts   BB code is On Smilies are On [IMG] code is On [VIDEO] code is On HTML code is Off Trackbacks are Off Pingbacks are Off Refbacks are On Terms of Use Agreement