Reading from text file and finding three highest numbers from test scores

I need help for this assignment:

Write a program that reads test scores (four scores for each student) from a file. The program should use value-returning functions to determine the test average. (The test average is the average of the three highest test scores.). The program should use priming read and a while loop that terminates when there is no more data in the file. The program should output the four test scores rounded to one decimal place and the average rounded to two decimal places to a file.

I am trying to read from a text file by this program, but no output file shows up
Also I don't know how to make it read the "three highest score either

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
#include <iostream>
#include <conio.h>
#include <fstream>
#include <iomanip>

using namespace std;

double FindAverage(double, double, double, double);

int main()
{
	
	ifstream inData;
	ofstream outData;
	double score1;
	double score2;
	double score3;
	double score4;
	double average;

	inData.open("c:\tests.txt");
	outData.open("c:\tests-output.txt");

	cout << "Data is being processed" << endl;

	
	outData << setw(15) << "Test 1" << setw(25) << "Test 2" << setw(30) << "Test 3" << setw(30) << "Test 4" << setw(30) << "Average" << endl;

	inData >> score1;
	inData >> score2;
	inData >> score3;
	inData >> score4;

	while (inData)
	{
		average = FindAverage(score1, score2, score3, score4);
		
		outData << fixed << showpoint << setprecision(2);
		outData << setw(15) << score1;
		outData << setw(25) << score2;
		outData << setw(30) << score3;
		outData << setw(30) << score4;
		outData << setw(30) << average;

		inData >> score1;
		inData >> score2;
		inData >> score3;
		inData >> score4;
	}

	inData.close();
	outData.close();

	getch();
	return 0;
}

double FindAverage(double score1, double score2, double score3, double score4)
{
	return (score1 + score2 + score3 + score4) / 4;
}


Please help!
Solved the input/output error

but still having trouble with the "three highest test scores"
To get the three highest scores, you have to change the FindAverage function to an if else statement ( compare the scores to each other)


If (score1<score2 && score1<score3 && score1<score4)
Return(Score2+score3+score4)/3;
Else if (score2<score1 && score2<score3 && score2<score4)
Return(Score1+score3+score4)/3;
Else if (score3<score1 && score3<score2 && score3<score4)
Return(Score1+score2+score4)/3;
Else
Return(Score1+score2+score3)/3;

- I don't know if you formatted your output like you are supposed to: test scores to one decimal point and averages to two.
Topic archived. No new replies allowed.