Ok...can anyone tell me why the while loop outputs the last bit of data twice?? if you can...that'd be cool...thanx
here's the code:
Code:
#include<fstream.h>
#include<iomanip.h>
void main (void)
{
ifstream inputfile;
ofstream outputfile;
int Max, Min;
float Avg, Num1, Num2, Num3, Num4, Num5, Num6, Num7;
float Total;
char Data[8];
inputfile.open("C:\\Hell\\Input.dat", ios::in);
outputfile.open("C:\\Hell\\Output.dat", ios::out);
if (!inputfile)
cout << "Your file is bad or does not exist. Please try again later.";
inputfile >> Data;
while (!inputfile.eof())
{
Max = 0;
Min = 1000;
inputfile >> Num1 >> Num2 >> Num3 >> Num4 >> Num5 >> Num6 >> Num7;
if (Num1 > Max)
Max = Num1;
if (Num2 > Max)
Max = Num2;
if (Num3 > Max)
Max = Num3;
if (Num4 > Max)
Max = Num4;
if (Num5 > Max)
Max = Num5;
if (Num6 > Max)
Max = Num6;
if (Num7 > Max)
Max = Num7;
if (Num1 < Min)
Min = Num1;
if (Num2 < Min)
Min = Num2;
if (Num3 < Min)
Min = Num3;
if (Num4 < Min)
Min = Num4;
if (Num5 < Min)
Min = Num5;
if (Num6 < Min)
Min = Num6;
if (Num7 < Min)
Min = Num7;
Total = (Num1 + Num2 + Num3 + Num4 + Num5 + Num6 + Num7);
Avg = (Total / 7);
outputfile << Num1 << " " << Num2 << " " << Num3 << " " << Num4 << " " << Num5 << " " << Num6 << " " << Num7 << " " << endl;
outputfile << "The biggest number is: " << Max << endl;
outputfile << "The smallest number is: " << Min << endl;
outputfile << "The total of those numbers is: " << setiosflags(ios::fixed) << Total << endl;
outputfile << "The average of those numbers is: " << setprecision(2) << Avg << endl;
outputfile << endl;
}
inputfile.close();
outputfile.close();
}
If you can tell me why it's being weird...that'd be cool...oh yeah...here's the data i'm using...lol
Data
346 130 982 90 656 117 595
415 948 126 4 558 571 87
42 360 412 721 463 47 119
441 190 985 214 509 2 571
77 81 681 651 995 93 74
310 9 995 561 92 14 288
466 664 892 8 766 34 639
151 64 98 813 67 834 369
the output goes ok...but...it does this...
The biggest number is: 834
The smallest number is: 64
The total of those numbers is: 2396
The average of those numbers is: 342.29
151 64 98 813 67 834 369
The biggest number is: 834
The smallest number is: 64
The total of those numbers is: 2396
The average of those numbers is: 342.29
WHY OH WHY DOES THE LAST ONE COME OUT TWICE! ACK!
Thanx again :-)