Problem with File input/output

I'm finishing a lab where I have to edit my old one to include file input and output. The program is supposed to read values from a file and perform calculations, then output the results to another file

these are the values read:

43
25
64
35
19
37
46

these are the results:

Blood drive period.7 (correct)
Average Pints-1.32228e+061 (wrong)
Highest Pints64 (correct)
Lowest Pints-9.25596e+061 (wrong)

the problem is, when I perform calculations, it's really weird because only my highest function works properly. In the original program, average, high, and low worked fine, I didn't edit any of the other functions.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;

int main()
{
	cout << "This is Vishant's pint program." << endl;
	char reset = 'n';
	double pints[24];
	double averagePints = 0;
	double highPints = 0;
	double lowPints = 0;
	int hours = 7;
	void getPints(double pints[], int hours);
	double getAverage(double pints[], int hours);
	double getHigh(double pints[], int hours);
	double getLow(double pints[], int hours);
	void displayInfo(int hours, double averagePints, double highPints, double lowPints);
	while (reset == 'n')
	{
		getPints(pints, hours);
		averagePints = getAverage(pints, hours);
		highPints = getHigh(pints, hours);
		lowPints = getLow(pints, hours);
		displayInfo(hours, averagePints, highPints, lowPints);
		cout << "End program?" << endl;
		cin >> reset;
	}
return 0;
}

void getPints(double pints[], int hours)
{
	int a;
	ifstream bloodInFile;
	bloodInFile.open("bloodDrive.txt");
	bloodInFile >> a;
	int count = 0;
	while (!bloodInFile.eof())
	{
		pints[count] = a;
		count++;
		bloodInFile >> a;
	}
	bloodInFile.close();
}

double getAverage(double pints[], int hours)
{
double totalPints = 0;
for (int i = 0; i < hours; i++)
{
	totalPints = totalPints + pints[i];
}
double completePints = totalPints / hours;
return completePints;
}

double getHigh(double pints[], int hours)
{
	double highest = pints[0];
	for (int i = 1; i < hours; i++)
	{
		if (pints[i] > highest)
		{
			highest = pints[i];
		}
	}
		return highest;
}

double getLow(double pints[], int hours)
{
	double lowest = pints[0];
	for (int i = 1; i < hours; i++)
	{
		if (pints[i] < lowest)
		{
			lowest = pints[i];
		}
	}
	return lowest;
}

void displayInfo(int hours, double averagePints, double highPints, double lowPints)
{
	ofstream bloodOutFile;
	bloodOutFile.open("bloodResults.txt");
	bloodOutFile << "Blood drive period.";
	bloodOutFile << hours << endl;
	bloodOutFile << "Average Pints";
	bloodOutFile << averagePints << endl;
	bloodOutFile << "Highest Pints";
	bloodOutFile << highPints << endl;
	bloodOutFile << "Lowest Pints";
	bloodOutFile << lowPints;
	bloodOutFile.close();
}
Topic archived. No new replies allowed.