HELP with functions in my program

This is my assignment:

•Before reading the scores in and displaying, print a header (example is in purple in the image below).
•Create a showScore() function to display a label and the score count and score value. (2 arguments: count and score).
•After the average is calculated, use the average as an argument in a function named getGrade() to determine a letter grade.
A 90-100
B 80- 89
C 70- 79
D 60- 69
F 0 - 59

•Update the summary function to display the letter grade in addition to the rest of the summary data.

so far I can read the scores in from my file just fine. the only part I am having with is creating the functions "showScore()" and "getGrade()". I am not sure how to create them and more importantly I am not sure how to implement them into my code to make it work and run the way I want. and I also do not know in what part of my program to put them in. I know one goes in the loop, but where? any help from anyone would be so much appreciated!! Thank you!
heres my code so far

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
100
101
int main()
{
    string filename;
    ifstream infile;
    int score, grade, count = 0, total = 0;
    float average;


    //splash();
    //welcome();

    cout << showpoint << setprecision(1) << fixed;

    system("CLS");
    cout << down8
         << over3 << "Enter a file name: ";
    cin >> filename;

    infile.open(filename.c_str());
    system("CLS");
    cout << down6;
    cout << over4 << "Summary of Scores" << endl;
    cout << over4 << "-----------------" << endl;
    if (infile)
    {
        while(!infile.eof())
        {
            infile >> score;
            if(score >= 0 && score <= 100)
            {
                count++;
                total += score;
                cout << over4 << score << endl;
            }
        }
        average = getAvg(count,total);

        summary(count,total,average);
        getGrade(grade);
        infile.close();
    }
    else
    {
        errorMsg(filename);
    }
    cout << down6;
    cin. get();
}

//function definition
float getAvg(int count,int total)
{
    float average;

    average = total / static_cast<float>(count);

    return average;    // functions can only return ONE value!
    //Any statement after return value will NEVER execute
}

int getGrade(int grade)
{
    float average;

    if(average >= 0 && average <= 59)
    {
        cout << "F" << endl;
    }
    if(average >=60 && average <= 69)
    {
        cout << "D" << endl;
    }
    if(average >= 70 && average <= 79)
    {
        cout << "C" << endl;
    }
    if(average >= 80 && average <= 89)
    {
        cout << "B" << endl;
    }
    if(average >= 90)
    {
        cout << "A" << endl;
    }
    return average;
}

//function prototypes
void summary(int number, int total, float average)
{
    cout << over4 << "Number of scores: " << setw(4) << number << endl;
    cout << over4 << "Scores total: " << setw(10) << total << endl;
    cout << over4 << "Average: " << setw(16) << average << "%" << endl;
    cout << over4 << "Grade: " << endl;
}

void errorMsg(string fName)
{
    cout << over3 << "\"" << fName
         << "\" could not be found!";
}  
I think you want getGrade() to return the letter grade, not print it. Then line 94 could be written as
cout << over4 << "Grade: " << getGrade(average) << endl;

As a general rule, it's usually a good idea to separate computing data from displaying it.
Yes that is exactly what I need. Thank you for the input. Its just setting it up is very difficult and i'm having a really hard time knowing how
Topic archived. No new replies allowed.