trying to calculate and display average of the four highest scores. NEED HELP!!

#include "stdafx.h"
#include <iostream>
using namespace std;

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

int main()
{
int s1, s2, s3, s4, s5;

cout << "I am staring in function main.\n";

getScore(s1, s2, s3, s4, s5);
cout << "Now back in main. The 5 test score are: " << endl;
cout << s1 << endl << s2 << endl << s3 << endl << s4 << endl << s5 << endl;

cout << "Now back in main." << endl;
cout << "The average of the 4 highest test scores is: ";
calcAverage(s1, s2, s3, s4, s5);
cout << s1 << endl << s2 << endl << s3 << endl << s4 << endl << s5 << endl;
return 0;
}

void getScore(int &s1, int &s2, int &s3, int &s4, int &s5)
{
cout << "Enter 5 test scores: ";
cin >> s1 >> s2 >> s3 >> s4 >> s5;

// Input Validation// while (s1 < 0 || s1 > 100 && s2 < 0 || s2 > 100 && s3 < 0 || s3 > 100 &&
s4 < 0 || s4 > 100 && s5 < 0 || s5 > 100)
{
cout << "Invaild value entered !!" << endl;
cout << "Please enter a value between 0 through 100: ";
cin >> s1 >> s2 >> s3 >> s4 >> s5;
}

}

void calcAverage(double s1, double s2, double s3, double s4, double s5)
{

cout << (s1 + s2 + s3 + s4 + s5) / 4 << endl;

}
Last edited on
Hi jrock,
I think U should write the problem statement.

Gud to see the code. But U can make it better If u would have used the "insert code" button while posting.

AnyWay I think If U r wondering why it is not providing the right output the problem lies below:

cout << (s1 + s2 + s3 + s4 + s5) / 4 << endl;
U r taking sum of five values, where as dividing it by 4 to get the Average of 5 numbers !!!
Last edited on
closed account (z05DSL3A)
jrock

Please post questions in one forum only! There are links to a couple of guidance articles at the bottom of this, please read them.

jrock wrote (in other forum):
| 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:
|
| a.) voidgetScore() 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 five scores to be entered.
|
| b.) voidcalcAverage() 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.
|
| c.) int findLowest() should find and return the lowest of the five scores
| passed to it. It should be called by calcAverage, who 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

Part a, says to use the function void getScore() to get a score...
1
2
3
4
void getScore(int& val)
{
...
} 


Part b, You would have to do somthing along the line of
1
2
3
4
sum equals the sum of values 1 through 5
sum equals sum minus findLowest()
average = sum divided by 4
display average


part c, you would have somthing like
1
2
3
4
5
lowest value equals 100
if value 1 is less than lowest then lowest equals value 1
if value 2 is less than lowest then lowest equals value 2
...
Return lowest




How To Ask Questions The Smart Way
http://www.cplusplus.com/forum/articles/1295/
How to put code into your postings
http://www.cplusplus.com/forum/articles/1624/
Last edited on
First, let it be known, mainly to Grey Wolf, being an ass to someone is not the most optimized way to solve a problem.

Next, on to helping jrock. Multiple functions isn't necessary for such a small task, you could just stick inside of main.

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
// four highest scores average.cpp : main project file.

#include "stdafx.h"
#include <iostream>

using namespace std;
using namespace System;

int main() 
{
	int scores[5], temp;
	do {
		cout << "Please enter a score: ";
		cin >> scores[0];
	} while(scores[0] < 0 || scores[0] > 100);

	for(int i = 1; i < 5; i++){
		do {
		cout << "\n\nPlease enter a score: ";
		cin >> scores[i];
		} while(scores[i] < 0 || scores[i] > 100);
		
		if(scores[i] < scores[0]) {
			temp = scores[i];
			scores[i] = scores[0];
			scores[0] = temp;
		}
	}

	double average = (scores[1] + scores[2] + scores[3] + scores[4]) / 4;
	cout << "\n\nAverage of the four highest scores: " << double(average) << "\n\n";

	return 0;
}


	
closed account (z05DSL3A)
PoliticalDestruction wrote:
| First, let it be known, mainly to Grey Wolf, being an ass to someone is not
| the most optimized way to solve a problem.

Exactly how was I being an ass to someone?

| Next, on to helping jrock. Multiple functions isn't necessary for such a
| small task, you could just stick inside of main.

It may not be necessary but it is what the OP has been asked to do!
Last edited on
thank you for your input about this program..GREY WOLF and POLITICAL DESTRUCTION.. both of you really help me out with this program.
jrock wrote:
| thank you for your input about this program..GREY WOLF and POLITICAL
| DESTRUCTION.. both of you really help me out with this program.

Your welcome. I am glad you asked, it was fun to make this.

Last edited on
Topic archived. No new replies allowed.