problem in arrays please help me out

q.Use a one-dimensional array to solve the following problem. Read in 20 numbers, each of which is between 10 and 100, inclusive. As each number is read, 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 entered.
code is
#include <iostream>
using namespace std;
void main()
{
int i,q,counter=0,j,w=0;
int a[10];
for( i=0;i<10;i++)
{
cout<<"enter 10 numbers";
cin>>q;
if(q>=10&&q<=100){
for( j=0;j<10;j++)
if(q==a[j])
{
counter++;
break;
}

if(counter==0){
a[w]=q;
w++;
}}
else
{
cout<<"you enter low or high number"<<endl;
cout<<"enter again"<<endl;
cin>>q;
}


}
for(int e=0;e<w;e++)
cout<<a[e]<<endl;
}
problem is that it is not showing the write output please help me in this program.
Initialize your variables before use them.
in array or other variables
like this a[]={0};
Do you understand what you are writing yourself?!

Read in 20 numbers
yes is understanding but can anybody solve my problem
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include<cstdlib>
#include<iostream>
using namespace std;
int main()
{
int a[10];
int value;
int zero=0;
int zero2=0;
int czero=0;
int ok=1;
int total=0;
for(int i=0;i<10;i++)
{
	value=0;
	cin>>value;
	if(value>=10&&value<=100)
	{
		while(czero>0)
		{
		
        if(value==a[zero2])
		{
		ok=0;
		}
		zero2++;
		czero--;
		}
				zero2=0;
		if(ok==1)
		{
			a[zero]=value;
	zero++;
		}
		
		
		zero2=0;
		ok=1;
			total++;
			czero=total;
	}
	else
	{
// bored to type
	return 0;
	}

}
zero2=0;
while(zero>0)
{
cout<<a[zero2]<<' ';

zero--;
zero2++;
}
cout<<endl;

system("PAUSE");
return 0;
}



my code :D if i understood u well
Topic archived. No new replies allowed.