-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.cpp
51 lines (43 loc) · 960 Bytes
/
Main.cpp
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
#include <iostream>
#include <fstream>
#include "console.h"
#include "error.h"
using namespace std;
struct gradesT {
int min;
int max;
double average;
};
void PrintGrades(gradesT grades)
{
cout << "min: " << grades.min << ", max: " << grades.max
<< ", average: " << grades.average << endl;
}
gradesT ReadScores(string filename)
{
ifstream scoresFile;
scoresFile.open(filename);
if (!scoresFile.is_open())
error("Couldn't open file");
int score;
int count = 0, sum = 0;
gradesT res;
res.min = 100;
res.max = 0;
while (scoresFile >> score) {
count++;
sum += score;
if (score < res.min)
res.min = score;
if (score > res.max)
res.max = score;
}
res.average = sum / double(count);
scoresFile.close();
return res;
}
int main() {
gradesT grades = ReadScores("scores.txt");
PrintGrades(grades);
return 0;
}