below is my code the whole program is for prompting user to enter 10 nos. b/w 20 to 100 it will while is there to check wheter the user entr the corect number or not, it will also check that the entered number is unique and was not previously entered by the user. at end of program simply it will display the non dublicate nos. whole program is correct but at end it is not displaying correct result. plz check the code n tell me wherz my mistake.

#include<stdio.h>
#include<conio.h>
#include<iostream.h>
main()
{
  int nTmp,j;
  //declares variable bflag th be of type bool & intializes bflag to false
  //bool is a data type whose value may be false or true
  bool bFlag=false;
  int a[10];
  cout<<"entr 10 numbers b/w 20 and 100"<<endl; 
  for(int i=0;i<10;i++) 
  { 
    cout<<"Enter Value"<<endl;
    cin>>nTmp; 
    while(!bFlag)
    { 
      ////Here we check first Condition 
      // no between 20 and 100 
      while((nTmp<20)||(nTmp>100)) 
      { 
        cout<<"enter no b/w 20 and 100"<<endl; 
        cin>>nTmp;
      } 
      j=0; 
      while(j<=i) 
      { 
        if(a[j++]==nTmp) 
        { 
          bFlag=false; 

        }
        bFlag=true; 
      } 
      if(bFlag==true) 
      { 
        //save variable 
        a[i]=nTmp; 
      }
    }
    //again make it false
    bFlag=false;
  }
  cout<<" the non dublicate nos are "<<a[i]<<endl;
  getch();
}

Code formatted and tags added. -Narue

Rose

my prob is that i need to print only dat numbers that r not repeated.like if i entered 50, 60, 80, 90, 99, 56, 50,98, 45, 99 so here 50 and 99 are reapeating so in the output ony 8 nos that r 50, 60, 80, 90, 99, 56, 98, 45 such that the nos that r repeating should not be displayed as u observe it in output.this is not diaplyind the ouput which i want.

for(i=0;i<10;i++)
cout<<" the non dublicate nos are "<<a<<endl;
rose

>whole program is correct but at end it is not displaying correct result.
Then the whole program is not correct. :rolleyes:

>#include<stdio.h>
This isn't needed.

>main()
This is illegal C++. Implicit int is not allowed, so you need to say:

int main()

>for(int i=0;i<10;i++)
This is not portable because you access i after the loop. i should be declared outside of the loop to be correct.

Compare this with what you have:

#include<iostream>

using namespace std;

int main()
{
  int nTmp,i,j;
  bool bFlag=false;
  int a[10];
  cout<<"entr 10 numbers b/w 20 and 100"<<endl; 
  for(i=0;i<10;i++) 
  { 
    while(!bFlag)
    { 
      cout<<"Enter Value"<<endl;
      cin>>nTmp; 
      ////Here we check first Condition 
      // no between 20 and 100 
      while((nTmp<20)||(nTmp>100)) 
      { 
        cout<<"enter no b/w 20 and 100"<<endl; 
        cin>>nTmp;
      } 
      for(j=0;j<i;j++) 
      { 
        if(a[j]==nTmp) 
        {
          cout<<nTmp<<" already exists"<<endl;
          break;
        }
      } 
      if(j==i) 
      { 
        //save variable 
        a[i]=nTmp; 
        bFlag=true;
      }
    }
    //again make it false
    bFlag=false;
  }

  cout<<" the non dublicate nos are "<<endl;
  for(i=0;i<10;i++) 
    cout<<a[i]<<endl;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.