>with this for statement i want to start a loop that generates 6 random and different numbers.
Your loop is a bit unusual:
>if (a == a && a == 0)
Of course a is going to be equal to a, you can remove that and just test for 0. Though since you want all different numbers simply testing for 0 doesn't help you much.
Perhaps if you kept a record of the numbers already produced and didn't increment the counter until a new number is found:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
static int is_saved ( int val, int *saved, int size )
{
int i;
for ( i = 0; i < size; i++) {
if ( saved[i] == val ) {
return 1;
}
}
return 0;
}
int main ( void )
{
int a, i = 0;
int saved[6];
srand ( (unsigned)time ( NULL ) );
while ( i < 6 ) {
a = rand() % 50;
if ( !is_saved ( a, saved, 6 ) ) {
saved[i++] = a;
}
}
printf ( "Your numbers are: " );
for ( i = 0; i < 6; i++ ) {
printf ( "%d ", saved[i] );
}
printf ( "Your bonus number is: %d\n", rand() % 50 );
return 0;
}
-Prelude