i was told to write program which generate unique 5 digit number ( for example 12345 is unique and 11234 not)
i have write following code
#include <iostream>
#include <stdlib.h>
#include <map>
using namespace std;
using std::rand;
const int k=99999-10234;
bool unique(int t){
map<int,int>my;
map<int,int>::iterator it;
while (t!=0){
++my[t%10];
t/=10;
}
for (it=my.begin();it!=my.end();it++){
if ( it->second>0) {
return false;
}
}
return true;
}
int main(){
int m=0;
m= 10234+ rand()%k;
if (unique(m)){
cout<<" unique number was generated =:"<<m<<" ";
}
else{
do{
m=10234+rand()%k;
if (unique(m)){
cout<<"unique number was generated"<<m<<" ";
break;
}
} while(!unique(m));
}
return 0;
}
but it does not show me any output please help me what is bad in my code?