Calculate the average, the highest and the lowest score of each student.

Can someone help me how the lowest is zero when printed? I have looked for 30 mins to find the mistake already. Nothing so far. Thanks in advance.




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
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;

double calcAverage (int first, int second, int third)
{
    double sum=0;
    double average=0.0;
    sum=first+second+third;
    average=sum/3.0;

    return average;
}

int findHighest (int first, int second, int third)
{
    int highest=0;

    if (first > highest)
        highest=first;
    if (second > highest)
        highest=second;
    if(third > highest)
        highest=third;

    return highest;
}

int findLowest (int first, int second, int third)
{
    int lowest=0;
    if (first < lowest)
       lowest=first;
    if (second < lowest)
        lowest=second;
    if(third <lowest)
        lowest=third;

    return lowest;
}


void printReport (string name, double average, int highest, int lowest)
{
    cout << name << " " <<setprecision(4)<< average << " " << highest << " " << lowest << "\n";
 }




int main()
{
int first=0,second=0,third=0,highest=0,lowest=0;
string name;
double average=0.0;

    fstream infile;
    infile.open("scores.txt");
    if (!infile)
    {
        cout<<"File open error"<<endl;
        return -1;
    }

    while(infile>>name>>first>>second>>third)
    {

        average = calcAverage(first,second,third);

        highest=findHighest(first,second,third);
        lowest=findLowest(first,second,third);
        printReport(name,average,highest,lowest);
    }
     infile.close();
     return 0;

}
I believe there just wasnt any scores less than 0, so (first < lowest) etc. conditions are never fire.
Topic archived. No new replies allowed.