Problem: 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 5 scores to be entered.

void calcAverage() should calculate and display the average of the 4 highest scores. This function should be called just once by main, and should be passed the 5 scores.

int findLowest() should find and return the lowest of the 5 scores passed to it. It should be called by calcAverage, which uses the function to determine one of the 5 scores to drop.

Validation: Don't accept test scores lower than 0 or higher than 100.

This is what I got so far. I cant use arrays since I havent gotten that far yet and please if you can explain to me what is going on so I can better understand the syntax, etc.

#include <iostream>
using namespace std;

void getScore(double s1, double s2, double s3, double s4, double s5);
void calcAverage(double s1, double s2, double s3, double s4, double s5);
int findLowest(double, double, double, double, double);

int main();

void getScore(double s1, double s2, double s3, double s4, double s5)
{
    cout << "Please enter 5 Test Scores 0 through 100: ";
    cin >> s1 >> s2 >> s3 >> s4 >> s5;

    while (s1 < 0 || s1 > 100 && s2 < 0 || s2 > 100 && s3 < 0 || s3 > 100 &&
           s4 < 0 || s4 > 100 && s5 < 0 || s5 > 100)
    {
        cout << "You have entered an invalid number\n";
        cout << "Please enter number 0 through 100 for each test score: ";
        cin >> s1 >> s2 >> s3 >> s4 >> s5;
    }
}

void getAverage(double s1, double s2, double s3, double s4, double s5)
{
    double sum,
           low,
           average;

    sum = s1 + s2 + s3 + s4 + s5;
    low = sum - findLowest(double lowest);
    average = low / 4;

}

int findLowest(double s1, double s2, double s3, double s4, double s5)
{
    double lowest,
           least;

    if (s1 < least) least = lowest;
    if (s2 < least) least = lowest;
    if (s3 < least) least = lowest;
    if (s4 < least) least = lowest;
    if (s5 < least) least = lowest;

    return lowest;
}

If you have writtern the code , you would not need someone else to make you understand what is going on .

If you have writtern the code , you would not need someone else to make you understand what is going on .

perhaps you misread what I put. I was saying to whom ever was willing to lend me a hand if they were to put any code in to explain why its that way, etc. But thanks for assuming!

perhaps you misread what I put. I was saying to whom ever was willing to lend me a hand if they were to put any code in to explain why its that way, etc. But thanks for assuming!

Please use code tags.

void getScore(double s1, double s2, double s3, double s4, double s5);
void calcAverage(double s1, double s2, double s3, double s4, double s5);
int findLowest(double, double, double, double, double);
void getScore(double s1, double s2, double s3, double s4, double s5);
void calcAverage(double s1, double s2, double s3, double s4, double s5);
int findLowest(double, double, double, double, double);

None of the parameters above are passed by reference, so anything you do to them inside the function will go away when the function returns.

void getScore() should ask the user for [COLOR="Red"]a[/COLOR] test score, store it in a [COLOR="Red"]reference parameter[/COLOR] variable, and validate it. This function should be called by main once [COLOR="Red"]for each of the 5[/COLOR] scores to be entered.

The spec calls for getScore to take a SINGLE parameter, not 5, and that parameter should be passed by reference, not by value. It should be called five times, not once.

Compare that with what you're doing:

void getScore(double s1, double s2, double s3, double s4, double s5);

5 parameters, not one, and all are passed by value. You want this:

void getScore (double& score);

Call it five times.

main is incorrect. main should be always be something like this (brackets, no semicolon):

int main ()
{
  // code
  return 0;
}

not this:

int main ();

VernonDozier,
why is there an & symbol in the function?
void getScore (double& score);

what does that do, etc?

VernonDozier,
why is there an & symbol in the function?
void getScore (double& score);

what does that do, etc?

& signifies that the parameter is passed by reference, not passed by value. If this is a new concept to you, google "C++ pass by reference" and "C++ pass by value". Here's a link that explains and looks pretty decent, but you should read it, plus a more thorough tutorial on it. Sections 7.1, 7.2, and 7.3 are relevant here.

http://www.learncpp.com/#Chapter7

Vernon,

After reading those articles, thanks btw!!, I cannot figure out how to get main to call the function 5 times and how would I store them to calculate the average?

Vernon,

After reading those articles, thanks btw!!, I cannot figure out how to get main to call the function 5 times and how would I store them to calculate the average?

Here's a skeleton that might help. It doesn't do any input validation and it doesn't correctly calculate the average. That will be up to you. But it gives a skeleton on how to pass the parameters.

#include <iostream>
using namespace std;


void getScore (double& score);
void calcAverage (double& avg, double score1, double score2, double score3, double score4, double score5);


int main ()
{
    double score1, score2, score3, score4, score5, avg;
    getScore (score1);
    getScore (score2);
    getScore (score3);
    getScore (score4);
    getScore (score5);
    calcAverage (avg, score1, score2, score3, score4, score5); 
    
    cout << "Average is " << avg;

    return 0;   
}


void getScore (double& score)
{
     cout << "Enter a score : ";
     cin >> score;
}


void calcAverage (double& avg, double score1, double score2, double score3, double score4, double score5)
{
     avg = 6.7; 
}

Thanks, I finally figured it out. The lowest doesnt return w/ grad1, couldnt figure that out but i got it to return the grad# instead. Still works. Thanks again!

#include <iostream>
using namespace std;

void getScore(double &grade);
void calcAverage(double,double,double,double,double);
int findLowest(double,double,double,double,double);

int main()
{
    double grade1, grade2, grade3, grade4, grade5;
    
    getScore(grade1);
    getScore(grade2);
    getScore(grade3);
    getScore(grade4);
    getScore(grade5);
    calcAverage(grade1,grade2,grade3,grade4,grade5);

cout << "This program calculates the average of 5 scores and drops the lowest\n";
    
}
void getScore(double &grade)
{
	static int count = 0;
	count++;
	cout << "Please enter in grade number " << count << ": ";
            cin >> grade;
            if ( grade < 0 || grade > 100 )
            {
                do 
                {
	cout << "Please enter in a valid number 0 through 100: "; 
                    cin >> grade;
                }
                while (grade < 0 || grade > 100 );
            }
}
void calcAverage(double score1, double score2, double score3, double score4, double score5)
{
    double lowest = 0;
    double average;

    lowest = findLowest(score1,score2,score3,score4,score5);
    average = ((score1 + score2 + score3 + score4 + score5) - lowest) / 4;
	cout << "The grade average is: " << average << endl;
    cout << "The lowest grade dropped was: " << lowest << endl;

}
int findLowest(double grad1, double grad2, double grad3, double grad4, double grad5)
{
    double average,
		   least,
		   lowDrop = 0;

    average = (grad1 + grad2 + grad3 + grad4 + grad5) / 5;
    cout << "The average before dropping the lowest grade:  " << average << endl;


    if(grad1 < 100)
	{
		least = grad1;
        lowDrop = grad1;
        return lowDrop;
	}
	else if(grad2 < 100)
	{
		least = grad2;
        lowDrop = grad2;
        return lowDrop;
	}
	else if(grad3 < 100)
	{
		least = grad3;
        lowDrop = grad3;
        return lowDrop;
	}
	else if(grad4 < 100)
	{
		least = grad4;
        lowDrop = grad4;
        return lowDrop;
	}
	else if(grad5 < 100)
	{
		least = grad5;
        lowDrop = grad5;
        return lowDrop;
	}

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.