-
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!
-
// Function to find duplicates
void output(int dedup[], int i3);
-
ugh i ALWAYS miss those things. =\
my program compiles fine now but after i enter the 10 numbers, the program just ends.
-
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!