Im new to c++ and i'm tryin to compute the standard deviation of a set of floating point numbers using a data file. here I started my program and skip over things i didn't really know but can someone plaese help me.
****************************************************************************

#include<iostream>
#incluse<fstream>
#include <cstdlib>
#include <cmath>

int main()
{
using namespace std;
ifstream in_stream;
ofstream out_stream;


Right in here i need help into what i put in the middle statement

}

double next,sum = 0;
double average;
double s_dev = 0;
int count = 0;
while(in_stream >> next)
{
sum = sum + next;
count++;
}
average = sum/count;

Recommended Answers

All 3 Replies

Before doing anything you have to know what the data file looks like. Can you post a few lines from it? Or just attach it to your post.

The data file is a set of floating point numbers. Here they are the ones I have in my data file:
1.2
3.3
1.5
2.9
2.5
2.1

The data file is a set of floating point numbers. Here they are the ones I have in my data file:
1.2
3.3
1.5
2.9
2.5
2.1

In order to do the standard deviation, you need to store each number for later use in either an array or a vector. You can do sum and average without storing the numbers, but you can't calculate the standard deviation before knowing the average. Thus set up an array or vector and read all of the data in.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.