My engineering computations teacher gave us an assignment that requires the program to read the text in a text file. The text in the file is a column of numbers. I used the code he gave us and when I ran the code, it just gave back a lot of values scrolling down the screen.
[code]
using namespace std;
#include <iostream>
#include <fstream>
ifstream Infile;
float InData[100];
int i;
int main()
{
Infile.open("data.txt");
i=0;
while(!Infile.eof())
{
Infile>>InData[i];
cout<<InData[i]<<"";
i++;
}
Infile.close();
cout<<"number of data points"<<i<<endl;
system("pause");
return(0);
}
If you can read the numbers when you open the file they aren't stored in a format compatible with float. Reading text-based numbers into a float (or double) variable will read garbage values.
Read your data using either a C-style char string or C++ std::string.
Personally I would recommend using C++ std::string. Read as a std::string and then use one of the string class functions to convert to a float.
Okay, so why don't you give it a try? In the code you posted I see no attempt to actually use the values retrieved from the file, other that the print out.
Do you know how to compute the mean and standard deviation?