가위바위보 하는 프로그램인데 디버그에서는 문제없고 릴리즈도 비주얼 스튜디오에서 켜지는데 저장된 exe 파일 누르면 종료되네요..
이런게 프로그램의 세계군요..
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <time.h>
#define DefeatCondition 3
char RockScissorsPaper[3]+ = { "가위", "바위", "보" };
char nResult[3][32] = { "비겼습니다.", "이겼습니다.", "졌습니다." };
int CurrentDefeat = 0;
int CurrentScore = 0;
int BestScore = 0;
FILE *BestScorefp = NULL;
int GetBestScore(void)
{
BestScorefp = fopen("BestScore.txt", "r");
fscanf(BestScorefp, "%d", &BestScore);
return BestScore;
}
void PrintBestScore(int BestScore)
{
printf("지금까지의 최다 연승 : %d\n\n", BestScore);
}
int InputErrorCheck(char nInput)
{
if (nInput == '1') return 0;
if (nInput == '2') return 0;
if (nInput == '3') return 0;
else printf("다시 키를 입력해주세요\n");
return 1;
}
int ComputerInput(void)
{
int ComputerInput;
srand((unsigned)time(NULL));
ComputerInput = rand() % 3;
return ComputerInput;
}
void ScoreManager(int WinLose)
{
if (WinLose == 1) CurrentScore++;
else if (WinLose == 2) CurrentDefeat++;
return;
}
void PlayGame(void)
{
char nInput = 0;
int ComputerRCP;
while (CurrentDefeat != DefeatCondition)
{
Start :
printf("[1] 가위 [2] 바위 [3] 보\t\t승리 : %d\t패배 : %d\n", CurrentScore, CurrentDefeat);
nInput = _getch();
if (InputErrorCheck(nInput) == 1) goto Start;
nInput = nInput - 49; //char형을 int형으로 변환
ComputerRCP = ComputerInput();
printf("Player : %s\tComputer : %s\n%s\n\n", RockScissorsPaper[nInput], RockScissorsPaper[ComputerRCP]
, nResult[(3 + nInput - ComputerRCP) % 3]);
ScoreManager((3 + nInput - ComputerRCP) % 3);
}
return;
}
void WriteBestScore(void)
{
BestScorefp = fopen("BestScore.txt", "r");
fscanf(BestScorefp, "%d", &BestScore);
if (CurrentScore <= BestScore) fclose(BestScorefp);
else
{
fclose(BestScorefp);
BestScorefp = fopen("BestScore.txt", "w");
fprintf(BestScorefp, "%d", CurrentScore);
}
fclose(BestScorefp);
return;
}
int main(void)
{
int BestScore = GetBestScore();
PrintBestScore(BestScore);
PlayGame();
WriteBestScore();
printf("당신의 승리횟수 : %d\n", CurrentScore);
return 0;
}
아 문제점 찾았네요.. 같은 폴더에 txt파일을 빼먹었네용