By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,406 Members | 1,031 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,406 IT Pros & Developers. It's quick & easy.

question on array dupes

P: 57
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

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.    int scores[20];
  6.    int value;
  7.    int dupes;
  8.    int count = 0;
  9.    cout << "Enter list: ";
  10.    for(int i = 0; i < 20; i++) {
  11.            cin >> value;
  12.            if(value == 0)
  13.                     break;
  14.  
  15.  
  16.            if (scores[i] == value)
  17.            {
  18.                 dupes = 1;
  19.            }
  20.  
  21.            if (dupes != 1)
  22.            {
  23.  
  24.            scores[count] = value;
  25.            count++;
  26.            }
  27.  
  28.             cout << scores[0]<< "," ;
  29.  
  30.            }
  31.         return 0;
  32. }
Nov 8 '06 #1
Share this Question
Share on Google+
1 Reply


Ganon11
Expert 2.5K+
P: 3,652
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.    int scores[20];
  6.    int value;
  7.    int dupes;
  8.    int count = 0;
  9.    cout << "Enter list: ";
  10.    for(int i = 0; i < 20; i++) {
  11.            cin >> value;
  12.            if(value == 0)
  13.                     break;
  14.  
  15.  
  16.            if (scores[i] == value)
  17.            {
  18.                 dupes = 1;
  19.            }
  20.  
  21.            if (dupes != 1)
  22.            {
  23.  
  24.            scores[count] = value;
  25.            count++;
  26.            }
  27.  
  28.             cout << scores[0]<< "," ; // This line is wrong!
  29.  
  30.            }
  31.         return 0;
  32. }
The marked line always prints the first value of scores - change it to

Expand|Select|Wrap|Line Numbers
  1. cout << scores[i] << ", ";
and try again.
Nov 8 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.