|
/* 이름 : Find_nbr.c
* 목적 : 이 프로그램을 임의의 수를 선택해서 사용자가 추측하게 한다
* 변환 값 : 없음
*/
#include <stdio.h>
#include <stdio.h>
#include <time.h>
#define NO 0
#define YES 1
void main(void)
{
int guess_value = -1;
int number;
int nbr_of_guesses;
int done = NO;
printf("\n\nGetting a Random number\n");
/* 난수 생성자를 사용할 차례 */
srand( (unsigned) time(NULL) );
number = rand();
nbr_of_guesses = 0;
while ( done == NO )
{
printf("\nPick a number between 0 and %d> ", RAND_MAX);
scanf( "%d", &guess_value ); /* 숫자를 구함 */
nbr_of_guesses++;
if (number == guess_value)
{
done = YES;
}
else
if (number < guess_value)
{
printf("\nYou guessed high!");
}
else
{
printf("\nYou guessed low!");
}
}
printf("\n\nCongratulations! You guessed right in %d Guesses!", nbr_of_guesses);
printf("\n\nThe number was %d\n\n", number);
}
|