Arrays and Number Repetition

I have an array of 10 digits, need to break up each digit as a separate int and then compare each digit to the other to see if there is a repetition.

Code so far:

for (i = 0; i < 10; i++)
{
temp = number % 10;
number = number / 10;
digits_seen[i] = temp;
}

What can I add in the code above, or separate to it, that will allow me to compare each digit to the next?
you can compare temp to digits_seen[i-1] when temp is greater than zero
There is an easy way if you think about it for a minute.

You don't care how many times you've seen a number; you only care that you saw it before.
This suggests using an array of booleans. To make lookup easy, the index into the array can be
the number you are looking up. So, for example, array[ 5 ] is set to true if you've seen a 5 so far.
Making progress, but still not there. This works on some runs, but not not on others, isn't consistent. Where is my error?

int main()
{

bool digits_seen[10] = {false};
char yes_no;
int number, temp;

do
{
cout << "Enter a number: " << endl;
cin >> number;

while (number > 0)

{
temp = number % 10;
if (digits_seen[temp])
break;
digits_seen[temp] = true;
number = number / 10;
}

digits_seen[temp] = false;

if (number > 0)
cout << "It has a repeated digit." << endl;
else
cout << "It has no repeated digits." << endl;

cout << "Do you want to enter another number? (y/n): " << endl;
cin >> yes_no;
You should include in the loop some of the following lines
Bazzy, what should be included?
There are lines outside of the loop (after it) that need to be inside.
Topic archived. No new replies allowed.