Thread: using arrays

  1. #1
    Registered User helloalyssa's Avatar
    Join Date
    Sep 2010
    Posts
    25

    using arrays

    hi everyone, i need some help with my assignment for the week. we're supposed to (taken directly from assignment page) "write a program that inputs an array of 10 integers from the user, and removes the duplicate array elements."

    the only error i get when i compile is: line 49, error #2169: expected a declaration. i know there's more than likely other errors. a tutor was helping me out. here is my coding:

    Code:
    
    #include<iostream>
    
    #include<iomanip>
    
    using namespace std;
    
    
    
    int main()
    
    {
    
      const int length = 11;    // holds variable for length
    
      int dedup[length];        // holds variables for length and array
    
      int array[10];
    
    
    
    cout << "Please enter 10 integers, hitting return after each one: "; 
    
    int i = 0;
    
    int i2 = 0;
    
    int i3 = 0;
    
    
    
    for(i=0; i < 10; i++)    // loop for user input of numbers
    
    
    
    cin >> array[i];
    
    
    
    for (i2 = 0; i2 < 10; i++) // i'm not sure what this line is for, a tutor was helping me but had to leave. 
    
    {
    
      if(array[i] == 0)
    
      array [i] = 200;
    
      if(array [i] == dedup[i2])
    
      {
    
        break;
    
      }
    
      else if(i == 9)
    
      {
    
        dedup[i3] = array[i];
    
        i3++;
    
      }
    
    }
    
     
    
      return 0;
    
    }
    
    
    
    // Function to find duplicates
    
    void output(int dedup[], int i3);
    
    {
    
      int count = 0;
    
      cout << "You entered" << i3 << "distinct numbers.";
    
    
    
      for (; count < i3; count++)
    
      {
    
        if(dedup[count] == 200)
    
        {
    
          dedup[count] = 0;
    
        }
    
        cout << dedup[count] <<" ";
    
        cout << endl;
    
      }
    
    }
    this is my last assignment for the semester and i'm desperate to finish it asap, i have other finals to study for. any help is extremely appreciated. thank you!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    // Function to find duplicates

    void output(int dedup[], int i3);
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User helloalyssa's Avatar
    Join Date
    Sep 2010
    Posts
    25
    ugh i ALWAYS miss those things. =\

    my program compiles fine now but after i enter the 10 numbers, the program just ends.

  4. #4
    Registered User
    Join Date
    Dec 2010
    Posts
    25
    Why use a number within a variable name? It can be quite confusing and I think it's bad practice. It is up to you though!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to create and manipulate Terabyte size Arrays with Win32API
    By KrishnaPG in forum Windows Programming
    Replies: 1
    Last Post: 11-05-2009, 04:08 AM
  2. pointers & arrays and realloc!
    By zesty in forum C Programming
    Replies: 14
    Last Post: 01-19-2008, 04:24 PM
  3. Replies: 16
    Last Post: 01-01-2008, 04:07 PM
  4. Need Help With 3 Parallel Arrays Selction Sort
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2005, 10:47 PM
  5. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 09:24 PM