Dropping a Score

This program is supposed to take the input of four scores, drop the lowest score and average the remaining three. The score range is (0.0 - 10.0). I have it so that it recognizes whether two scores are the same but then it just eliminates them both. How do I fix this issue?

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
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
// Local Variables.
  float j1, j2, j3, j4;
  
  string greet = "Welcome Judges! Enter your scores (0.0-10.0) and I will average the highest 3!";
// User Prompt.
  cout << greet << endl;
  cin >> j1 >> j2 >> j3>> j4;
// Determining which number to drop.
  if (j1 <= j2 || j1 <= j3 || j1 <= j4)
  cout << showpoint << fixed << setprecision(1) << (j2 + j3 + j4)/3.0;
  else if (j2 <= j1 || j2 <= j3 || j2 <= j4)
  cout << showpoint << fixed << setprecision(1) << (j1 + j3 + j4)/3.0;
  else if (j3 <= j1 || j3 <= j2 || j3 <= j4)
  cout << showpoint << fixed << setprecision(1) << (j1 + j2 + j4)/3.0;
  else if (j4 <= j1 || j4 <= j2 || j4 <= j3)
  cout << showpoint << fixed << setprecision(1) << (j1 + j2 + j3)/3.0;
  
  else if ((j1 + j2 + j3 + j4) > 40.0 || (j1 + j2 + j3 + j4) < 0.0)
  cout << "Please use integers from (0-10)";
  else
  cout << "Please use integers from (0-10)";
  }
Hello RiggityWrecked,

Are you familiar with "vector"s? That would very easily cout out most of the if/else statements. Another advantage to vectors is that they can grow or shrink as needed. So, if you add more judges it is not a problem.

Otherwise you would need other code to determine which judge has the highest score. This could be another set of if/else if statements or reworking what you have.

Looking at what you have I am thinking that (j1 < j2 && j1 < j3 ...) would work better to find the highest score. An it might need to be (j1 > j2 && j1 > j3 ...). Without testing I believe the > an && would find the highest number better.

I noticed that J1... are defined as floats, but the last lines of the program say to use integers. This does not match. Also your numbers should be small enough to use floats, but doubles are the preferred type.

Hope that helps,

Andy
Thanks Andy. Yeah I'm sure vectors would be useful but this is only chapter 5 of the textbook so we haven't covered that yet. let me give your solution a try and I'll get back to you with the result.
UPDATE: The && solved all the issues I was having. Thanks!
Last edited on
Hello RiggityWrecked,

Thinking about the if/else if statements the order in which you do the might make a difference, e.g.,:
j4 > j1 && j4 > j2...
j3 > 1j && j3 > j2...
j2 > j1...
j1 > j2...

I did not try this yet, but my original testing with your original code an even with y changes did not work right.

Hope that helps,

Andy
Topic archived. No new replies allowed.