Thread: can't get an array to show.

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    13

    can't get an array to show.

    how would i get it to repeat the array that the user puts in ?

    my current output i get:

    "Please enter the size that you would like of an array from 0-100 :
    3
    Now enter 3 characters :
    1
    2
    3
    The numbers you entered are: -858993460Press any key to continue"


    Code:
    #include<iostream>
    
    using namespace std;
    void deleterepeats(char a[], int& arraysize);
    
    int main ()
        {
         int index_used = 0;
            int arraysize, a[100];
          
     
            cout<<"Please enter the size that you would like of an array from 0-100 : \n";
            cin >>arraysize;
    
            cout<<"Now enter "<< arraysize<<" characters :\n";
        
    
            int k= 0;
            
            while (k<arraysize)
            
                {
                cin>> a[k];
                k++;
                }
    
           cout <<"The numbers you entered are: ";
            
          
    	   for (int index = 0; index < arraysize; index++);
    	   {
    			
    		   index++;
    
    		   cout << a[index];
    	   }
    	   
    	   
        
      
        
        return 0;
    
        }
    Last edited by IXxAlnxXI; 10-31-2006 at 04:18 AM.

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Code:
    for (int index = 0; index < arraysize; index++) //remove it ;
    	   {
    			
    		   // remove it index++;
    
    		   cout << a[index];
    	   }
    see comments
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Code:
    cout<<"Now enter "<< arraysize<<" characters :\n";
    Perhaps you should prompt for numbers, not characters . . .

    Code:
    cout << a[index];
    You might want to print some whitespace after this, such as a newline or a space, because otherwise the numbers in your output will run together; that is, if a[] contains (1, 2, 3, 55, 99), your program would print "1235599".
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. from 2D array to 1D array
    By cfdprogrammer in forum C Programming
    Replies: 17
    Last Post: 03-24-2009, 10:33 AM
  3. Array of Pointers to Arrays
    By Biozero in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 02:31 PM
  4. Replies: 6
    Last Post: 11-09-2006, 03:28 AM
  5. Type and nontype parameters w/overloading
    By Mr_LJ in forum C++ Programming
    Replies: 3
    Last Post: 01-02-2004, 01:01 AM