Hi! I have this Code Breaker thing to do and I don't know what's wrong. I'm just a newbie, please help me out.
Here's the instruction:
The program would initially generate 4 distinct random digits number (no 2 digits are the same / unique). Then the user need to guess the random number. The program would give clues by giving 'black' and 'white' markers.
(black marker - exact number in correct digit position
white marker - exact number in wrong position)
The user would also choose the level of difficulty he/she prefers (easy - 10 chances; average - 7 chances; difficult - 5 chances)
So far, here's what I've done (no code regarding difficulty yet 'coz the basic still doesn't work )
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void) {
int i, stime;
long ltime;
int x, j;
int black = 0;
int white = 0;
int code[4];
int easy[4];
ltime = time(NULL);
stime = (unsigned) ltime/2;
srand(stime);
code[i] = rand() % (9999-1000+1) + 1000;
printf("%d", code[i]);
printf("\n**CODE BREAKER**\n");
printf("CHANCE #1\n");
printf("Enter Guess: ");
scanf("%d", &easy[4]);
if(code[0] == easy[0]) {
black = black + 1;
}
for(i = 1; i < 4; i++) {
if(code[0] == easy[i]) {
white = white + 1;
}
}
if(code[1] == easy[1]) {
black = black + 1;
}
if(code[1] == easy[0]) {
white = white + 1;
}
for(i = 2; i < 4; i++) {
if(code[1] == easy[i]) {
white = white + 1;
}
}
if(code[2] == easy[2]) {
black = black + 1;
}
if(code[2] == easy[3]) {
white = white +1;
}
for(i = 0; i < 2; i++) {
if(code[2] == easy[i]) {
white = white + 1;
}
}
if(code[3] == easy[3]) {
black = black + 1;
}
for(i = 0; i < 3; i++) {
if(code[3] == easy[i]) {
white = white + 1;
}
}
if(black == 4) {
printf("Congratulations! You guessed the number right!\n");
} else {
printf("%d Black Marks\n%d White Marks", black, white);
}
}