Help with assignment for class.

Hello everyone! This is my first post on the site! I was hoping the community here could help me out with an assignment I had in class.



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. To make your programming easier, if a number is out of range (greater than the upper limit or less than the lower limit), then let the program replace it with upper or lower limit numbers.

Hint: Use double Array and for loop statement to store each Judge’s score

Hint: Use highest variable with the initial value of 0, and lowest variable with the initial value of 10, in order to find out the highest and the lowest scores .

*** sample output

Please enter the difficulty level(1.2 - 3.8): 1

Enter the score of judge 1: 5

Enter the score of judge 2: 4

Enter the score of judge 3: 3

Enter the score of judge 4: 2

Enter the score of judge 5: 1

Enter the score of judge 6: 6

Enter the score of judge 7: 7

Scores = { 5 4 3 2 1 6 7 }

Difficulty level = 1.2

Total score = 14.4


This is what I have so far. I'm a complete beginner so please have mercy!


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
  #include <iostream>

using namespace std;

 

double highest = 0;

double lowest = 10;

double difficulty = 0;

float score [6];

 

int main ()

{



                cout << "please enter the difficulty level(1.2 - 3.8):" << endl;

                cin >> difficulty;

                               

                cout << "Enter the score of judge 1: " << endl;

                cin >> score[6];

                 for (score = 0; score < 6; score++)
				 cout << "Did this work?" << endl;             

               

               

 

system("pause");

return 0;
We aren't going to do your homework for you, but some pointers are not out of the question.


After reading your code, I'm guessing you just picked up a C++ book/course no more than a few weeks ago. I'll attach some tutorial pages that will help you with this program.

http://www.cplusplus.com/doc/tutorial/control/
http://www.cplusplus.com/doc/tutorial/variables/
http://www.cplusplus.com/doc/tutorial/arrays/
Your guess is right, I started the class three weeks ago. I would have asked a tutor for help, but unforunately my school doesn't have a tutor for this course.
The resources here at http://www.cplusplus.com are phenomenal, and helped me out allot when I was first learning.

You need to review variable(& array) management, and the for loop structure.

In your current code, you are attempting to use an array to to the work of an integer...not gonna work very well...

Not quite there. Since you need to read in 7 scores you need to create a loop of 7 times, have your keyboard input inside the loop and store the value in the index of the array set by the loop variable.

Like:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

#include <iostream>
using namespace std;

int main()
{

	float scores[7];

	// create a loop to loop 7 times (0-6)
	// as array index's start at 0
	for (int i = 0; i < 7; i++)
	{
		cout << "Enter score for Judge " << i + 1 << ": ";
		cin >> scores[i];
	}

	return 0;
}


I have purposely not written the whole thing for you, but provided the example to show you where you have gone wrong in your code - hope this helps.
closed account (j3Rz8vqX)
What question in particular are you asking?

hint: Include curly brackets around the for-loops embedded data.
1
2
3
4
5
6
for(int i=0;i<7;i++)
{
    cout << "Enter the score of judge "<<i+1<<": ";
    cin>>score[i];
    cout<<endl;
}

Last edited on
Thank you so much Softrix!!! This is exactly the kind of response I was hoping to see on this site! I really don't want someone to just write the code for me, I'd never learn anything that way. I just wanted examples of what I did wrong, or didn't know how to do at all, and examples of the right way to do it.
Your welcome :)
I actually have another question for you guys if you don't mind. The part where I need to total the scores together is giving me some issues. I also am not sure how I would make it throw out the two lowest scores while adding the rest together? Any help or hints are greatly appreciated!


Current code:




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
#include <iostream>

using namespace std;

 

double highest = 0;

double lowest = 10;

double difficulty = 0;

float score [7];

 
float total = 0;


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];
				 }          

               

               

               

 

system("pause");

return 0;

}
Your first post said the lowest and highest needed canceled out...

You have lowest and highest variables already, so... Each score that is entered, compare to both. If the score is more accurate than the current value, save the score. At the end, just subtract the two values from your total.

1
2
3
4
5
6
7
8
9
10
11
/*
Let _MAX be the maximum possible value
Let _MIN be the minimum possible value
*/
int largest = _MIN;
int smallest = _MAX;
for (...) {
	cin<<x;
	if (x<smallest) smallest=x;
	if (x>largest) largest=x;
}


^^ To give you an idea..

As rssair demonstrated two simple IF statements would sort that out for you.

Just some advice to make your code a lot more readable, try to keep your code indentation right because as your projects get larger it will become less readable and harder to work out the flow of your code.

Topic archived. No new replies allowed.