Can anyone identify why the line : if(code == rand() && attempt != 3) not executed even I'm entered a correct code that generated by the rand().
#include <stdio.h>
#include <stdlib.h>
#include<time.h>
int main(void)
{
int code, attempt = 0;
srand(time(0));
for(int i = 0; i<1; i++)
printf("Your code is %d ", rand());
do{
printf("\nEnter code: ");
scanf("%d", &code);
attempt++;
}while ( code != rand() && attempt != 3);
if(code == rand() && attempt != 3)
{
printf("\n Correct code");
printf("\n");
}
else
{
printf("Incorrect code\n");
}
return 0;
}