ETC

퀴즈

성엽이 2013. 3. 13. 17:58
//일정 범위(0~20)의 수(firstNum)를 랜덤으로 생성합니다.
//사용자는 그 수(secondNum)를 맞춥니다.
//10 이상 차이나면 "차이가 너무 큽니다!" 라고 뜸 //fN +10
//10 이하 차이나면 "가까이 있습니다!" 라고 뜸 //fN -10
//5이하 차이나면 "아깝다!" 라고 뜸 //fN -5
//그 수를 맞출 시 "딩동댕!" 이라고 뜸 //fN -printf

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(void)
{
  int fn;
  int sn;
  srand(time(NULL));
  fn = rand() % 21;
  printf("%d", fn);
  while(1)
  {  
    printf("숫자를 입력해주세요: ");
    scanf("%d"&sn);
    if (fn == sn)
    { 
      printf("딩동댕!\n");
      break;
    }
    if((sn <= fn-10)||(fn+10 <= sn))
    {
      printf("차이가 너무 큽니다!\n");
    }
    else if ((fn-5 <= sn)&&(sn <= fn+5))
    {
      printf("아깝다!\n");
    }
    else
    {
      if((fn-10 < sn)||(sn < fn+10))
      {
        printf("가까이 있습니다!\n");
      }
    }
  }
  return 0;