One-dimensional array output problem

i look out this site for solution for this question :
One-dimensional array output problem
This is a class assignment from the book "C++ How to Program 8/E" by Deitel. Problem 7.15

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.
and read some replies but when i ran the cods they dont work correctly !!!!and i found out that codes isnt answer for this problem so i write this code that work correct.
It will compile fine, run fine, give all the proper errors if you enter the wrong number etc. The problem is with the output. It will output the unique values but then it continues to output garbage until in crashes Microsoft Visual Studio 2010.


tekrar : means non unique
adad : value
dobarabar: duplicate
20ta adad beyne 10 ta 100 vared konid : inter 20 values
adad haye gheir tekrari: unique numbers
adadaee ke zakhireh shodan: saved numbers






# include <iostream>
using namespace std;


int main()
{
const int SIZE = 20;
int a[SIZE] = {0};
int b[SIZE]={0};
int s = 0;
int dobarabar;
int tekrar;
int adad;
int k=0;
int i = 0;
int j = 0;

cout << "20ta adad beyne 10 ta 100 vared konid:\n";


for ( i = 0; i < SIZE;)
{
dobarabar = 0;

cin >> adad;


if ( adad >= 10 && adad <= 100 )
{
for ( j = 0; j < i; j++ )
{
if ( adad == 2*a[ j ] )
{
dobarabar = 1;
break;
}
}


if ( !dobarabar )
{
a[s ] =adad;
++s;

}
b[i]=adad;


++i;

}
else
cout << "adad na dorost \n";
}

cout << "adad haye gheir tekrari\n";



for ( int h = 0; h <i; h++ )
{
tekrar=0;
for(int r=0;r<i;r++)
{
if (r!=h){
if( b[h]==b[r]){tekrar=1; }}

}
if(tekrar==0){cout<<b[h]<<" , ";}
}
cout<<"\n adadaee ke zakhireh shodan : \n";
for(int h=0;h<s;h++)cout<<a[h]<<" , ";

int r;
cin>>r;
}
by thanks from RBGH

Could you post it in English and put code tags?
Sorry. It looks you're having a compiler problem. It run perfectly on MinGW-w64 and on my same one (MSVC++2010). I already had a problem like this. Try going to the setup/control panel unninstall and choosing "repair" for the program. Try unninstalling the (only) command line tools, downloading it again from Microsoft's site and installing. If nothing gets better, unninstall and install again. Or maybe it's just a code problem :).
salam,

codeto ba gcc compile kardam moshkeli nadasht.
Topic archived. No new replies allowed.