473,385 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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
1 1232
Ganon11
3,652 Expert 2GB
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

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

Similar topics

3
by: ScottH | last post by:
I was looking for thw SQL to delete dupes from a table, and came across this. All who saw it agreed in principle, but I can't quite figure out the logic. If we are deleting all rows whose rowid...
27
by: karan.shashi | last post by:
Hey all, I was asked this question in an interview recently: Suppose you have the method signature bool MyPairSum(int array, int sum) the array has all unique values (no repeats), your...
0
by: gdarian216 | last post by:
my question is my array is set to a size of 20 but the user can input less. I was writting if statements to get rid of the dupes and was wondering if i would have to go through it all 20 times or is...
1
by: gdarian216 | last post by:
I am trying to write a program that will input numbers in a array and then loop throught the array and look for dupes. The final output of the array should have the numbers in the array printed only...
3
by: gdarian216 | last post by:
I am writting a program that gets a list of numbers from a user no more then 20 integers and checks for dups. If zero is entered it stops entering numbers to array. I then need to output the entered...
12
by: joestevens232 | last post by:
Hello Im having problems figuring out how to remove the duplicate entries in an array...Write a program that accepts a sequence of integers (some of which may repeat) as input into an array. Write...
12
by: joestevens232 | last post by:
Hello, I'm having a little problem with my code...I have the program written but its just not doing what I want and needs a minor tweak and I've been trying to fix it for ohurs and can't find a...
2
by: Tyrone Slothrop | last post by:
I am writing a script to upload data to a delimited text file. The data is in the format: recordID \t the rest of the data ... It is significant that the recordID's are unique and that the...
10
by: username88 | last post by:
I am having trouble with a query for my database. It is a name & address database with columns like firstname, lastname, email, etc. I am trying to show dupes in my 20,000 name database. I have...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.