@coder777 , yes I deleted the else, but it gives the wrong number.
Try 4 3 3 2 1, and it gives 4 as the identical score, but I want it to be 3.
It seems it is only considering the first element of the array.
Because identical = 4 at the beginning and
I simplified the program for you, do you know what approach is necessary now? The output gives the last element that is entered on the screen.
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
|
#include <iostream>
using namespace std;
int main() {
//Reference: Problem Solving with C++ (pg. 381)
const int SIZE = 5;
int score[SIZE];
cout << "Enter 5 scores: " << endl;
cin >> score[0];
int identical;
for (int b = 1; b < SIZE; b++){
cin >> score[b];
}
for (int a = 0; a < SIZE; a++){
identical = score[a];
for (int i = 1; i < SIZE; i++){
//cin >> score[i];
if (identical == score[i] && a!= i){
identical = score[i];
}
}
}
cout << "The identical score is: " << identical << endl;
return 0;
}
| |
@LukeShen, yes that is the second stage of the problem. After getting it to work for atleast one number, then I need to find a way to see if I can have 3 and 2, BOTH as the identical score if I enter 4 3 3 2 2 as my input values.
I simplified the code above, still has a bug. Do you know what I should do next?