/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int throwDice();
int getUserGuess();
void playGuessingGame();
int throwDice(){
return rand() % 6 + 1;
}
int getUserGuess(){
int guess;
printf("주사위에 나올 숫자를 맞혀보세요(1~6): ");
scanf("%d",&guess);
return guess;
}
void playGuessingGame(){
int userGuess, diceResult;
// do while 문은 한번은 실행
do{
userGuess = getUserGuess();
diceResult = throwDice();
printf("주사위 결과 : %d\n",diceResult);
if(userGuess == diceResult){
printf("축하합니다. 정답입니다!\n");
}
else{
printf("아쉽네요 다시 시도하세요.\n");
}
}
while(userGuess != 0);
}
int main()
{
srand(time(NULL));
printf("숫자 만들기 게임을 시작합니다,\n");
playGuessingGame();
printf("게임 종료\n");
return 0;
}