Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<iomanip>
- using namespace std;
- double average(double *, int);
- int howManyA(double *, int);
- int main()
- {
- // Variable declaration
- int size = 0;
- double average1 = 0;
- int countOfA = 0;
- double *numbers = nullptr;
- cout << fixed << setprecision(1);
- //Ask user for how many test score they need and store it into size
- cout << "Enter number of test score: ";
- cin >> size;
- cout << endl;
- numbers = new double[size];
- // A loop that will ask for score and inputs into array NUMBER until it is full depending on the size the user inouts
- for (int i = 0; i < size; i++)
- {
- cout << "Input score for " << (i + 1) << ": ";
- cin >> numbers[i];
- while (numbers[i] < 0)
- {
- cout << "Input valid score for " << (i + 1) << ": ";
- cin >> numbers[i];
- }
- }
- //Function call to display the average
- average1 = average(numbers, size);
- cout << "\nThe average test score is " << average1 << endl;
- //Function to display how many scores above 89
- countOfA = howManyA(numbers, size);
- cout << "There are " << countOfA << " scores above 89";
- //This is used to delete the dynamic memeory created
- delete[] numbers;
- system("pause");
- return 0;
- }
- //Function that will get the array and user size, add up all the scores in a loop and divide by the size
- double average(double * score, int numScores)
- {
- double total = 0;
- for (int i = 0; i < numScores; i++)
- {
- total += *(score + i);
- }
- return (total / numScores);
- }
- //Function that will loop through all the scores, and add one every time it comes across a score that is 90 and above
- int howManyA(double * score, int numScores)
- {
- int total = 0;
- cout << numScores << endl;
- for (int i = 0; i < numScores; i++)
- {
- //cout << score[i] << endl;
- cout << i << endl;
- if (score[i] >= 90)
- {
- total += 1;
- }
- return total;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement