now i'm using the for loop things for my mastermind game,but.....it still got a randoming problem just like the first time i use with if else..
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int guess(int);
int main()
{
int digits;
srand((unsigned)time(NULL));
printf("\nWelcome To Mastermind!\n");
printf("How Much Digits Do You Want To Play:\n");
scanf("%d",&digits);
guess(digits);
return 0;
}
int guess(int code)
{
int get_random,get_guess,checking,checking2,right,place;
int guess_code[code-1];
int secret_code[code-1];
right = 0;
place = 0;
for(get_random=0;get_random<code;get_random++)
{
secret_code[get_random] = rand()%10;
printf("%d",secret_code[get_random]);
}
printf("\n I Have Made %d Digit For You To Guess..\n",code);
for(get_guess=0;get_guess<code;get_guess++)
{ printf("Guess #%d:",get_guess+1);
scanf("%d",&guess_code[get_guess]);
}
for(checking=0;checking<code;checking++)
{
if(secret_code[checking]==guess_code[checking])
{
right = right + 1;
secret_code[checking] = -1;
}
for(checking2=0;checking2<code;checking2++)
{
if(secret_code[checking] == guess_code[checking2])
{
place = place + 1;
secret_code[checking] = -1;
}
}
}
printf("\nYou have placing %d code at a right place and %d code at a wrong place..\n",right,place);
if(right==code)
{
printf("\nCongratulations,You have won the game!!\n");
return 0;
}
else
{
guess(code);
}
}
this is what i do,anyone can help me??