How to determine the lowest number from a list of numbers.

I have been assigned to write a program that utilizes functions. I must use a function to acquire 6 test scores, a function to drop the smallest value of the test scores, and then a function to calculate the average of the 5 highest test scores. Then call each function in main. I think I have the program mostly figured out just need help understanding how to exclude the lowest number. Any help would be greatly appreciated. Here is my code the function I'm working on is in line 88. Also I am getting a warning about the { in line 90 and 95 that states "expected a declaration," could someone fill me in on what that is implying.

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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
 /* This Program calculates the average of a group of test scores where the lowest score in the group is dropped.  

It will ask the user for a test score, store it in a reference parameter variable, and validate it.

This function will only be called by the main once for each of the six scores to be entered.  (So 6 times)

It will validate that the test scores are >= 0 and <= 100.

calcAverage should calculate and display the average of the five highest scores.  This function is to be called just once by main,
and must be passed the six scores.

int findLowest should find and return the lowest of the lowest scores passed to it.  It will be called by calcAverage, which uses the function
to determine wich of the six scores to drop.*/


#include<iostream>
#include <iomanip>

using namespace std;


void getScore1 ()
{
	int
		testscore = 0;

	cout << "What is the test score on the first test? \n";
	cin >> testscore;
	if
		(testscore <= 0 || testscore >=100);
	cout << "Error please enter a test score value between 0 & 100. \n";
}
void getScore2()
{
	int
		testscore = 0;

	cout << "What is the test score on the second test? \n";
	cin >> testscore;
	if
		(testscore <= 0 || testscore >= 100);
	cout << "Error please enter a test score value between 0 & 100. \n";
}
void getScore3()
{
	int
		testscore = 0;

	cout << "What is the test score on the third test? \n";
	cin >> testscore;
	if
		(testscore <= 0 || testscore >= 100);
	cout << "Error please enter a test score value between 0 & 100. \n";
}
void getScore4()
{
	int
		testscore = 0;

	cout << "What is the test score on the fourth test? \n";
	cin >> testscore;
	if
		(testscore <= 0 || testscore >= 100);
	cout << "Error please enter a test score value between 0 & 100. \n";
}
void getScore5()
{
	int
		testscore = 0;

	cout << "What is the test score on the fifth test? \n";
	cin >> testscore;
	if
		(testscore <= 0 || testscore >= 100);
	cout << "Error please enter a test score value between 0 & 100. \n";
}
void getScore6 ()
{
	int
		testscore = 0;

	cout << "What is the test score on the last test? \n";
	cin >> testscore;
	if
		(testscore <= 0 || testscore >=100);
	cout << "Error please enter a test score value between 0 & 100. \n";
}
int findLowest = 0 ();		// should find and return the lowest of the scores passed to it. It must be called by calcAverage,
							// which uses the function to determing which of the six scores to drop.
{
	findlowest =  getScore1+getScore2+getScore3+getScore3+getScore4+getScore5+getscore6;
}

void calcAverage();		// calculate and display the average for the five higest scores 
{
	calcAverage = findlowest / 5; 
}



int main()
{
	cout << "This program will acquire 6 test scores and drop the lowest score, it will then calculate the\n";
	cout << " the average of the 5 remaining test scores." << endl << endl;
	getScore1;
	getScore2;
	getScore3;
	getScore4;
	getScore5;
	getScore6;
	calcAverage;

	cout << "The average of the 5 highest scores is: "  << calcAverage;
	return 0;
}
Last edited on
On lines 90&95 you put a semicolon at the end and then had a body.
Please don't write 5 extra getScore functions for no reason.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
Returns an array of scores.
*/
int* getScores()
{
	constexpr int noOfTests{ 6 };
	int scores[noOfTests] = {};

	for(int i{}; i < noOfTests; i++) {
		cout << "Score on test " << i+1 << " : ";
		cin >> scores[i];
		if(testscore <= 0 || testscore >= 100) {
			cout << "Error please enter a test score value between 0 & 100. \n";
			return nullptr;
		}
		// add some other error checking statements here
		// what if the user enters a non-numerical character, such as, 'a'?
	}
	return scores;
}

if(testscore <= 0 || testscore >=100);        // I don't think you meant to put a semicolon here 
Last edited on
"void getScore() should ask the user for a test score, store it in a reference parameter variable, and validate it. This function must be called by main once for each of the six scores to be entered (so 6 times)." This is a quote from my assignment. The way I understand it is I have to write it 6 times, does this actually mean I just need to call it in main 6 times. I know there are better ways to create a program for this outcome but it is for a homework assignment.
1
2
3
4
5
6
7
8
9
10
// int& score : reference to int parameter
void getScore(int& score)
{
	std::cout << "What is the test score? \n";
	std::cin >> score;
	if(score <= 0 || score >=100) {
		std::cout << "Error! Please enter a test score value between 0 & 100. \n";
		score = -1;		// -1 to indicate an error
	}
}


I don't think your teacher would want you to create a function six times, when you can just create it once and call it six times.
Topic archived. No new replies allowed.