"Lowest score drop" C++ problem

Hey guys i will just type out the problem from my textbook and then post code below that, I will admit i am a bit confused im sure there are several errors in my code but the only errors im getting right now are that my functions findLowest and calcAverage "does not take 5 arguments" line 22 and 23 in main().
Thanks for any help you can give!

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 referance parameter variable, and validate it. This function should be called by main once for each of the five scores to be entered.
void calcAverage()-should calculate and display the average of the four highest scores. This function should be called just once by main and should be passed the five scores.
int findLowest()-should find and return the lowest of the five scores passed to it. It should be called calcAverage, which uses the function to determine which of the five scores to drop.
input validation: do not accept test scores lower than 0 or higher than 100.


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
#include "stdafx.h"
#include <iostream>
using namespace std;

void getScore(int & test);
void calcAverage(int test1, int test2, int test3, int test4, int test5);
int findLowest(int test1, int test2, int test3, int test4, int test5, int lowest);

int main()
{
	int test1, test2, test3, test4, test5, lowest;

	getScore(test1);
	getScore(test2);
	getScore(test3);
	getScore(test4);
	getScore(test5);

	lowest = findLowest(test1, test2, test3, test4, test5);
	calcAverage(test1, test2, test3, test4, test5, lowest);

	return 0;
}

void getScore(int &score) 
{
	cout << "Please enter the score: ";
	cin >> score;

	while (score < 1 || score >100)
	{
		cout << "Please enter a score between 0-100:";
		cin >> score;
	}
}

int findLowest(int test1, int test2, int test3, int test4, int test5)
{
	int lowest = test1;

	{
		if (test2 < lowest)
			lowest = test2;
		else if (test3 < lowest)
			lowest = test3;
		else if (test4 < lowest)
			lowest = test4;
		else if (test5 < lowest)
			lowest = test5;
	}
	return lowest;
}

void calcAverage(int test1, int test2, int test3, int test4, int test5,int lowest)
{
	double average;

	average = test1 + test2 + test3 + test4 + test5 - lowest / 4;
	cout << "The average is: " << average << endl;
}
1
2
void calcAverage(int test1, int test2, int test3, int test4, int test5);
int findLowest(int test1, int test2, int test3, int test4, int test5, int lowest);

These don't match your function definitions. lowest should be on calcAverage.

average = (test1 + test2 + test3 + test4 + test5 - lowest) / 4;

Put parenthesis so the order of operations is correct.
Having so many similar arguments on a function can't be a good idea.
You should pass an array or use varargs instead.
1
2
3
4
5
6
7
8
9
10
11
12
//calcAverage(10, 5, 1, 2, 3, 4, 5);
void calcAverage(int lowest, int count, ...) {
    va_list args;
    va_start(args, count);
    double average = 0.0;
    for (int i=0; i<count; ++i)
	 average += va_arg(args, int);
    va_end(args);
    average -= lowest;
    average /= count;
    cout << "The average is: " << average << endl;
}

1
2
3
4
5
6
7
8
9
10
11
//calcAverage(10, 5, {1, 2, 3, 4, 5});
void calcAverage(int lowest, int count, int const test[])
{
	double average = 0.0;
	for (int i=0; i<count; ++i)
	      average += test[i];
	average -= lowest;
	average /= count;
	cout << "The average is: " << average << endl;
}

Last edited on
I feel like an idiot everytime i post on here.. thanks again boys! Also @Ihatov we weren't allowed to used arrays unfortunately.
Registered users can post here. Sign in or register to post.