This is my code! I created a file containing only 7 numbers from 1-7. When I run the program the 7 shows as the highest number but 3 shows as the lowest number??? and the average as -9.3!!!! I can't figure what's wrong with it! can someone please help me?
Code:
#include <fstream>
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
ifstream in_stream;
double min, max=0;
double number=0;
double sum=0, count=0, average;
in_stream.open("D:\numbers.txt");
in_stream >> min;
in_stream >> max;
while (number != 0)
{
in_stream >> number;
sum += number;
count ++;
}
if (count > 0)
average = sum/count;
if (in_stream >> number)
{
min = max = number;
while (in_stream >> number)
{
if(number< min)
{
min = number;
}
if (number> max)
{
max = number;
}
}
in_stream.close();
cout << "The largest value in the file is " << max << "\n";
cout << "and the smallest value in the file is " << min << "\n";
cout << "Average is "<< average << endl;
cout << "\n";
}
return 0;
}

