# simple program help

• 10-07-2007
JayDilla
simple program help
SUP!, well i need help, im using visual C++, and i need to write a simple program that reads 100 numbers from 1 to 100 on a txt file, calculates their average, and the standard deviation and then inputs the standard deviation and average into the original file at the bottom:? .....k i know you start off with the basic library's you'll be using and the basic setup and such,, but from there on i am completely lost8O ,........be great if someone could help me writing this out so i can understand what i should be doing..shouldn't take long since i was peeping the forum and people seem C++ savy here...

btw the file im using is called data.txt...and is in the "Temp" folder of my c drive...THIS is attempt so far ....keep in mind im mad beginner ...in essence i need help in the whole std deviation part.

THANKS!

btw this is my code so far, be great if someone could tell me if im ok so far, aslo how i could do the standard deviation, i cant find a way to do it..
Code:

```#include <iostream> #include <cmath> #include <fstream> #include <iomanip> using namespace std; int main() {     float sum = 0, StdDev = 0;     int x = 0;     ifstream inFile;     inFile.open("data.txt");     while ( inFile >> x )         {                 sum += x;         }            inFile.close();         ofstream outFile( "data.txt", ios::app );         outFile.seekp( ios::end );         outFile << sum << endl;         outFile.close();            return 0; }```
• 10-08-2007
Salem
1. Rule 5
2. Do you know what "standard deviation" means in mathematical terms?

I would leave off the "append result to file" part until everything works, otherwise you will end up processing whatever junk you wrote to the file the next time you run the code.
• 10-08-2007
```#include <iostream> #include <fstream> #include <string> using namespace std; int main() { string line; int x; x=0;   ifstream myfile ("tst.txt");   if (myfile.is_open())   {     while (! myfile.eof() )           {       getline (myfile,line);       x=x+1;       cout << line << endl;           }     myfile.close();   }     else cout << "Unable to open file";     cout<<"Sum is "<<x<<endl;     getchar(); }```