/******************************************************************************
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;
}