Array Help
I need to have the user enter five numbers and check to make sure none of them are the same.
Here is my code:
1 2 3 4 5 6

void userNumbers(int usernum [5]){
for (int i=0; i<5; i++){
cout << "Please enter your " << i+1 << " lottery number ";
cin >> usernum[i];
}
}

I had to pass this array to this function. How can i check to make sure the user doesnt enter the same number twice?
I also need to make sure the numbers the user enters are between 1 and 59.
Last edited on
Here are five numbers.
3 6 12 3 5
Are any of them the same? How did you tell that? Explain to me how I can work it out for myself.
I know how to compare two numbers to check if there the same... i just dont know how to compare it to an entire array
just give u some concept.
think over your self
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

int number[5];
int i;
for( i = 0 ; i < 5 ; i++ ){
cout << "Enter number " << (i+1) << " : ";
cin >> number[i];
for( int j = 0 ; j < i; j++ ){
if( number[i] == number[j] ){
cout << "Number same ! " << endl;
i;
}
}
}
for( int j = 0 ; j < 5 ; j++ ){
cout << number[j] << " ";
}

Topic archived. No new replies allowed.