I can't get this program to work right. It reads and displays the file it's supposed to, but it won't figure out the max and display it. I've posted this a couple times, but none of the responses, which are appreciated, have worked. I'm a newb at this so any help is appreciated.
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int i;
char filename[81], input_line[81];
double data[11];
cout << "Enter the file name." << endl;
cin.getline(filename, 80);
ifstream file_in(filename);
if(!file_in)
{
cout << "Error! No file!";
return -1;
}
while(1)
{
for(i=1; i<=11 && !file_in.eof(); i++)
{
file_in.getline(input_line, 80);
cout << input_line << endl;
}
if(file_in.eof())break;
{
double max = data[11];
for(i=1; i<=max; i++);
if(max<data[11])max=data[i];
cout << "The maximum Magnitude is " << max;file_in.close();
return 0;
}
}
}
There is so much wrong I don't know where to start but just a few things
your data variable is not initialised
you read the line into input_line but don't put it into data (I assume that is where you want it) if(file_in.eof())break; so do not go on to the remainder of the code? for(i=1; i<=max; i++); will do nothing with the ; at the end.