Duplicate Elimination with array) 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 isn’t a duplicate of a number already read. After
reading all the values, display only the unique values that the user entered. Provide for the “worst
case” in which all 20 numbers are different. Use the smallest possible array to solve this problem.
I understand the logical step:
1.ask user input value
2.check value in the range
3.check value repeat or not
4.display only unique value
I try the small size array and see how it works
the difficult of this problem is remove the duplicate number.
I try at least 2 nights, hopefully someone can help me
my attempt: let the input in the range as show below
but compiler gives me some wire numbers after I run.
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
|
void Dea::Input()
{
cout<<"Enter any number between 10 and 100, 4 times \n";
do{
cin>> input;//user input
//check input the range
if (10>=input && input <=100)
a[count]=input;
++count;
} while(count<4);
}
void Dea::display()
{
for(int count=0;count<4;count++)
cout<<a[count]<<" \n";
}
|