online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
#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; } //do~while문 대신 while문의 무한루프로 작성해봤습니다. void playGuessingGame() { int userGuess, diceResult; while (1) { // 무한 루프 시작 userGuess = getUserGuess(); // 매 반복마다 입력 받기 // 입력값이 0이면 반복 종료 if (userGuess == 0) { printf("게임을 종료합니다.\n"); break; //완전히 빠져나감 } if(!(userGuess >=1 && userGuess<=6)){ // (userGuess<1 || userGuess>6)으로도 쓸 수 있음 printf("잘못 입력되었습니다. 1~6사이의 숫자로 다시 입력해주세요.\n"); continue; //프로그램 종료 하는 게 아니라 다시 while문 안쪽으로올라감 } diceResult = throwDice(); printf("주사위 결과: %d\n", diceResult); if (userGuess == diceResult) { printf("축하합니다! 숫자를 맞췄습니다.\n"); } else { printf("아쉽습니다. 다시 시도하세요.\n"); } } } // 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; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue