Created
May 7, 2015 01:25
-
-
Save OlafSamael/e15d5e744c66d278cbd7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <fstream> | |
#include <algorithm> | |
#include <cmath> | |
using namespace std; | |
void readNumbersFromFile(string filename){ | |
string line1; | |
float sum=0.0, value=0.0, sdev=0.0; | |
int counter=0; | |
ifstream myfile(filename.c_str()); | |
myfile.is_open(); | |
while(getline(myfile,line1)){ | |
value=atoi(line1.c_str()); | |
sum=sum+value; | |
counter++; | |
sdev=sqrt((pow(value-(sum/counter),2)/value)); | |
} | |
cout << "Total: " << sum << endl; | |
cout << "Number of values: " << counter << endl; | |
cout << "Average: " << sum/counter << endl; | |
cout << "Standard deviation: " << sdev << endl; | |
} | |
int main(){ | |
readNumbersFromFile("numbers.txt"); | |
system("pause"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment