dimanche 29 novembre 2020

Calculating test grade averages without using arrays or min/max in C++

I am currently very sleep deprived, mashing buttons into my keyboard , on an assignment that i procrastinated. Which, obviously, is my own fault, but if anyone on here could give some pointers of the use of functions here, i'd greatly appreciate it. The assignment is as follows:

"Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions:

void getScore() should ask the user for a test score, store it in a reference parameter variable, and validate it. This function should be called by main once for each of the 6 scores to be entered. Use a local static variable for which score is to be entered.

void calcAverage() should calculate and display the average of the five highest scores. This function should be called just once by main and should be passed the six scores. Include 2 decimal places on the result. This is passed data by value.

double findLowest() should find and return the lowest of the six scores passed to it. It should be called by calcAverage, which uses the function to determine which of the six scores to drop. This is passed data by value.

Do not use the min or max C++ functions."

What i'm failing to discover is how i can use a void function to pass data back to int main. My code so far is a stringy mess of errors, but i'm not sure how else to approach this one.



#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
double getScore(double);
double calcAverage(double);
double findLowest(double);
int main()
{
    
    double score = 0;
    double combinedScore = 0;


    getScore(score);

    calcAverage(combinedScore);

    findLowest();

}

double getScore(double score)
{
    double grade;
    int testNum = 1;

    cout << "Enter the test " << testNum << " grade :";
    cin >> grade;
    while (grade < 0)
    {
        cout << "Invalid entry! Must be at least zero.";
        cin >> grade;
    }
    while (testNum <= 6)
    {
        cout << "Enter the test " << testNum << " grade :";
        cin >> grade;
        if (grade < 0)
        {
            cout << "Invalid entry! Must be at least zero.";
            cin >> grade;
        }
        else
        testNum++;
        cout << "Enter the test " << testNum << " grade :";

        return (grade);
    }
}

void calcAverage()
{
    
}

double findLowest()
{

}

Thanks in advance for anything that points me in the right direction.

Aucun commentaire:

Enregistrer un commentaire