Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Mar 26th, 2008, 12:27 AM   #1
mychorhizzae
Newbie
 
Join Date: Mar 2008
Posts: 1
Rep Power: 0 mychorhizzae is on a distinguished road
duplicate numbers in arrays

Hi, I've been lurking here for a while now and decided to make an account to get help. The program I'm trying to write is supposed to:
Read in 20 numbers,
each of which is between 10 and 100, inclusive. As each number is read in, validate
it and store it in the array only if it is not a duplicate of a number already read.
After reading all the values, display only the unique values that the user has
entered.

I have the program functionally working except I don't know what to do for the duplicate cases. Is there an easy way to skip the value entered if duplicate?

#include <iostream>
using namespace std;
#include <iomanip>




int main() {
    int idx = 0;
    int list[20];
    int n;
    int i;
    
    cout << "Enter 20 integers between 10 and 100: " << endl;
    
    for (i=0; i<20; i++){ // user inputs 20 numbers
       
    cin >> n;
    
    if (n < 10 || n > 100){  // input must be between 10 and 100
    cout << "invalid entry" << endl;
}
            list[idx] = n;  //sets each number to the next element in array
              ++idx;

}
    for ( int j = 0; j < 10; j++ )
      cout << list[ j ] << " ";  // print numbers in array
        
    system("pause");
    return 0;
}
mychorhizzae is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
prime numbers now with arrays gmann145 C++ 2 Feb 19th, 2008 4:55 PM
code to add numbers in an array truBlu1 Java 9 Oct 12th, 2007 10:08 PM
Arrays or Vectors? can342man C++ 2 Apr 20th, 2006 3:57 PM
Arrays in PHP MrMan9879 PHP 6 Jan 12th, 2006 9:18 PM
Median/Mode in arrays? {Need help} Java|Tera Java 27 Nov 29th, 2005 10:50 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:47 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC