So the code runs and for the most part, does what I want it to do. The only issue is that when the password equals 1000 The print statement "Trying password: 1000" does not print before the statement that the computer has cracked the password which I know results from the fact that because they are equal to each other the code skips to the else if statement. Is there a way to get it so that the "Trying password:1000" prints before it prints that it cracked the password?
#include <stdio.h>
#include <stdbool.h>
int password;
int attack = 1000;
int num = 1;
bool repeat = true;
int main()
{
printf("Please enter a 4 digit password:\n");
scanf("%4d", &password);
while (repeat)
{
if (password < 1000 || password > 9999)
{
printf("Please enter a 4 digit password.\n");
scanf("%4d", &password);
}
if (attack != password)
{
printf("Trying password: %4d\n", attack++);
num=num+1;
}
else if (attack == password)
{
printf("Computer cracked the password in %4d tries\n", num);
repeat = false;
}
}
return 0;
}