D
Developwebsites
user enters non-repeating 100 numbers.
how do i determine that numbs do not repeat?
is this code correct?
also, once a repeated number has been found, lets say
I enter 345 twice, how do i break out of loop?
could someone test this with random(1-1000).
const int MAX=100;
int Numb[MAX];
bool exists;
cout<<"Enter "<<MAX<<" numbers";
for(int t=0;t<MAX;t++)
{
cout<<'\n';
cin>>Numb[t];
if (t>0) {
do {
exists = false;
for(int x=0;x<t;x++)//should this be a while instead?
{
if (Numb[x]==Numb[t]) {
exists = true;
cout<<"\nNumber "<<Numb[t]<<" already exists.\n";
cin>>Numb[t];
//break goes here?
}//if
}//for
}//do
while(exists == true)
}//if
}
how do i determine that numbs do not repeat?
is this code correct?
also, once a repeated number has been found, lets say
I enter 345 twice, how do i break out of loop?
could someone test this with random(1-1000).
const int MAX=100;
int Numb[MAX];
bool exists;
cout<<"Enter "<<MAX<<" numbers";
for(int t=0;t<MAX;t++)
{
cout<<'\n';
cin>>Numb[t];
if (t>0) {
do {
exists = false;
for(int x=0;x<t;x++)//should this be a while instead?
{
if (Numb[x]==Numb[t]) {
exists = true;
cout<<"\nNumber "<<Numb[t]<<" already exists.\n";
cin>>Numb[t];
//break goes here?
}//if
}//for
}//do
while(exists == true)
}//if
}