question on array dupes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gdarian216
    New Member
    • Oct 2006
    • 57

    question on array dupes

    I am tring to get rid of dupes and his code is taking the first input and repeating it. I don't know why.

    this is what i have so far can anyone help

    Code:
    #include <iostream>
    using namespace std;
    
    int main() {
       int scores[20];
       int value;
       int dupes;
       int count = 0;
       cout << "Enter list: ";
       for(int i = 0; i < 20; i++) {
               cin >> value;
               if(value == 0)
                        break;
    
    
               if (scores[i] == value)
               {
                    dupes = 1;
               }
    
               if (dupes != 1)
               {
    
               scores[count] = value;
               count++;
               }
    
                cout << scores[0]<< "," ;
    
               }
            return 0;
    }
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    Code:
    #include <iostream>
    using namespace std;
    
    int main() {
       int scores[20];
       int value;
       int dupes;
       int count = 0;
       cout << "Enter list: ";
       for(int i = 0; i < 20; i++) {
               cin >> value;
               if(value == 0)
                        break;
    
    
               if (scores[i] == value)
               {
                    dupes = 1;
               }
    
               if (dupes != 1)
               {
    
               scores[count] = value;
               count++;
               }
    
                cout << scores[0]<< "," ; // This line is wrong!
    
               }
            return 0;
    }
    The marked line always prints the first value of scores - change it to

    Code:
    cout << scores[i] << ", ";
    and try again.

    Comment

    Working...