howManyA's function

I am a very beginner to coding, and do not speak English that well, forgive me.
I am trying to make a code that will ask user for test score, print average, and find the amount of 90s and above, or "A"s. This is my code.

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

#include <iostream>
#include <iomanip>
using namespace std;

double findAverage(double* score, int numScores);
int howManyA(double* score, int numScores);

int main()
{
    double *score;   // To dynamically allocate an array
    int numScores,   // To hold the number of days of sales
    count;           // Counter variable
    
    
    // Get the number of test scores they will enter.
    cout << "How many scores will you be entering? ";
    cin >> numScores;
    while (numScores < 0)
    {
        cout << "Please enter a positive number: ";
        cin >> numScores;
    }
    
    // Dynamically allocate an array
    score = new double[numScores];
    
    
    // Get the sales figures for each day.
    
    
    cout << "Enter the test scores below.\n";
    
    
    for (count = 0; count < numScores; count++)
        {
        cout << "Test Score " << (count + 1) << ": ";
        cin >> score[count];
        
        while (numScores < 0)
            {
        cout << "Please enter a positive value: ";
        cin >> score[count];
            }
        }
    
    findAverage(score,numScores);
    howManyA(score,numScores);
    return 0;
}

double findAverage(double* score, int numScores)

{
    double total = 0.0,
          scores = 0.0;
    for (int count = 0; count < numScores; count++)
    {
        total += score[count];
    }
    
    double average = total / numScores;    // Display the results
    cout << fixed << showpoint << setprecision(2);
    cout << "/nAverage Score: " << average << endl;
    
    
    // Free dynamically allocated memory
    
    
    delete [] double scores;    
    scores = 0;
    
    
    // Make score point to null.
    return 0;
}

int howManyA(double* score, int numScores)
{
    for (int count = 0; count < numScores; count++)
    {
        
    }
    
    return 0;
}




I do not know how to make a function that finds the amount of A's. That is my problem. Any help is appreciated.
Last edited on
If an A is score >= 90.0 I would assume you could do:

1
2
3
4
5
6
7
8
9
10
int howManyA(double* score, int numScores)
{
    int numberOfA = 0;
    for (int count = 0; count < numScores; count++)
    {
        if (score[count] >= 90.0) numberOfA ++;
    }
    return numberOfA;
}

Does that help?
In the function findAverage, line 70, you aren't deleting the pointer variable score. I assume you meant to delete score like this delete[] score;. Although, from what I see, you shouldn't be deleting score in that function because you then proceed to pass that variable into the function howManyA. Thus, you should delete score inside of main after you are done using it.
Last edited on
Thank all of you, I think it looks good. i will still test a few more times.
Topic archived. No new replies allowed.