I’m trying to write a program for the “bulls and cows” game. The game explanation: The program has a secret 4 digit number. The user has to guess the numbers. If the number is: 1235 And the use guessed: 1592 The number of bulls is 1, because the user guessed a correct number and the position of it, And the number of cows is 3, Because the user only guessed the numbers.
I’m trying to make the guess function, but the output is weird. It’s still not a function, just trying to make it work first. I have to use an array of chars and an int. the user needs to have an option to type 0 as one of the digits.
The code:
#include <stdio.h>
#include <conio.h>
/A function that gets 4 chars from the user and checks if they're valid
int main()
{
char guess[5]= {0};
int i=0;
printf("please enter a 4 digit interger\n");
for (i=0;i<4; i++) {
scanf("%d", &guess[i]);
printf("your guess is:");
for (i=0;i<4; i++) {
printf("%d", guess[i]);
}
}
getch();
return 0;
}
The weird output is:
Your guess is: -1281300
Why doesn’t it show the number the user gets? Thank you so much for helping!