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.
#include <iostream>
#include <iomanip>
usingnamespace 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 = newdouble[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.
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.