Homework Problem

Hey all!

I am trying to get one of my homework problems to work, but something is going wrong with it. Would appreciate any advice you guys can give me on it. Thanks a bunch! It does all of the inputting part correctly, but the output is where the problem is.

In the sport of diving, seven judges award a score between 0 and 10, where each score may be a floating-point value. The highest and lowest scores are thrown out and the remaining scores are added together. The sum is then multiplied by the degree of difficulty for that dive. The degree of difficulty ranges from 1.2 to 3.8 points. The total is then multiplied by 0.6 to determine the diver’s score.
Write a computer program that inputs a degree of difficulty and seven judges’ scores, and outputs the overall score for that dive. The program should ensure that all inputs are within the allowable data ranges.

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
#include<iostream>
using namespace std;
int main()
{
	int score[7];
	double difficulty;
	double total=0;
	int best = 10;
	int worst = 0;
	cout << "Enter the difficulty level (1.2 - 3.8):";
	cin >> difficulty;
	if (difficulty < 1.2)
		difficulty = 1.2;
	if (difficulty > 3.8)
		difficulty = 3.8;
	for (int i = 0; i < 7; i++)
	{
		std::cout << "Enter the score of judge " << i + 1 << ": " << std::flush;
		std::cin >> score[i];
		if (score[i] > 10)
			score[i] = 10;
		if (score[i] < 0)
			score[i] = 0;
		if (score[i] > best)
			best = score[i];
		if (score[i] < worst)
			worst = score[i];
		total += score[i];
		
	}
	double Total = 0;
	for (int i = 0; i < 7; i++)
		Total += score[i];
	cout << "Scores = ";

	for (int i = 0; i < 7; i++)
	{  
		cout << score[i] << " " << std::flush;
		total = ((total - (best + worst))*  0.6);
		{
			cout << endl;
			cout << "Total score = " << total << endl;
			cout << "Difficulty level = " << difficulty << endl;
		}
	}
	return 0;
}
Last edited on
How many totals should there be? One.
How many do you show? Seven.

Count the sum first. (You do that on lines 31-33.)
Remove the outliers once.
Show the result once.
So I kind of re-did the whole thing cause I saw that it looked pretty wonky in the first place. There is something wrong with my calculations here as well, not sure what it is. Appreciate the help though.
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
#include <iostream>
using namespace std;

double highest = 0;
double lowest = 10;
double difficulty = 0;
double score[7];
double total = 0;
double highlow, subtotal, totalscore;


int main()

{
	cout << "Please enter the difficulty level(1.2 - 3.8):" << endl;
	cin >> difficulty;

	for (int i = 0; i < 7; i++)
	{
		cout << "Enter the score of judge " << i + 1 << ": " << endl;
		cin >> score[i];
		total += score[i];
	}
	highlow = score[0] += score[6];
	subtotal = score[7] -= highlow;
	totalscore = subtotal *= 0.6;
	cout << "Total Score = " << totalscore << endl;

	return 0;
}
Sorry, but your original lines 1-33 are ok.


On the new attempt:

* Your line 24 is same as:
1
2
score[0] = score[0] + score[6];
highlow = score[0]

Why to change score[0] ? Are 0 and 6 really the best and worst?

* There is no score[7] in array score. Out-of-range error.

* If your loop has already computed sum 'total', why don't you use that value for anything?
Topic archived. No new replies allowed.