함수 호출 후, return 값 질문요
Creator
질문 제목 : 함수 호출 후, return 값 질문요do-while 반복문 안에서 함수호출을 한다음에 함수에서 계산 후 return값으로 되돌려줘야되는데
되돌려받질 않아요 ... ㅠㅠ 어디가 잘못된건지 ...
소스해석 = 주사위 굴리는 게임이고 엔터를 칠때마다 모든 플레이어의 주사위가 동시에
굴려져서 그만큼씩 증가한다. 단, 특정 숫자가 됬을 경우 특정 사용자만 함수호출한다.
함수에서 3칸뒤로를 걸렸을 경우, -3 을 해준후 return 을 해준다.
총 값이 50을 먼저 넘긴사람이 있을 경우 반복문을 탈출한다.
마지막으로 각 사용자의 총 점수를 출력해주고 프로그램을 종료한다.
아래 소스 첨부했어요. 쫌 기네요 ;;질문 내용 :
#include stdafx.h
#include windows.h
#include iostream
#include time.h
using namespace std;/* 문구 위치 지정 */
void gotoxy(int x, int y)
{
coord cursor;
cursor.x=x;
cursor.y=y;
setconsolecursorposition(getstdhandle(std_output_handle), cursor);
}/* 1p 게임 함정 */
int p(int own, int three)
{
int temp;
switch(own)
{
case 6: own=own-1; cout★ = 1칸 뒤로endl; break;
case 15: own=own+1; cout★ = 1칸 앞으로endl; break;
case 20: own=own-1; cout★ = 1칸 뒤로endl; break;
case 29: own=own+3; cout★ = 3칸 앞으로endl; break;
case 33: own=0; cout★ = 첨부터 다시endl; break;
case 36: own=own+1; cout★ = 1칸 앞으로endl; break;
case 42: own=own+2; cout★ = ◆과 위치바꾸기endl; temp=own; own=three; three=temp; break;
case 48: own=own-8; cout★ = 8칸 뒤로endl; break;
case 49: own=0; cout★ = 첨부터 다시endl; break;
}
return own;
}/* 2p 게임 함정 */
int pp(int two, int own)
{
int temp;
switch(two)
{
case 6: two=two-1; cout● = 1칸 뒤로endl; break;
case 15: two=two+1; cout● = 1칸 앞으로endl; break;
case 20: two=two-1; cout● = 1칸 뒤로endl; break;
case 29;case 29: two=two+3; cout● = 3칸 앞으로endl; break;
case 33: two=0; cout● = 첨부터 다시endl; break;
case 36: two=two+1; cout● = 1칸 앞으로endl; break;
case 42: two=two+2; cout● = ★과 위치바꾸기endl; temp=two; two=own; own=temp; break;
case 48: two=two-8; cout● = 8칸 뒤로endl; break;
case 49: two=0; cout● = 첨부터 다시endl; break;
}
return two;
}/* 3p 게임 함정 */
int ppp(int three, int four)
{
int temp;
switch(three)
{
case 6: three=three-1; cout◆ = 1칸 뒤로endl; break;
case 15: three=three+1; cout◆ = 1칸 앞으로endl; break;
case 20: three=three-1; cout◆ = 1칸 뒤로endl; break;
case 29: three=three+3; cout◆ = 3칸 앞으로endl; break;
case 33: three=0; cout◆ = 첨부터 다시endl; break;
case 36: three=three+1; cout◆ = 1칸 앞으로endl; break;
case 42: three=three+2; cout◆ = ■와 위치바꾸기endl; temp=three; three=four; four=temp; break;
case 48: three=three-8; cout◆ = 8칸 뒤로endl; break;
case 49: three=0; cout◆ = 첨부터 다시endl; break;
}
return three;
}/* 4p 게임 함정 */
int pppp(int four, int two)
{
int temp;
switch(four)
{
case 6: four=four-1; cout■ = 1칸 뒤로endl; break;
case 15: four=four+1; cout■ = 1칸 앞으로endl; break;
case 20: four=four-1; cout■ = 1칸 뒤로endl; break;
case 29: four=four+3; cout■ = 3칸 앞으로endl; break;
case 33: four=0; cout■ = 첨부터 다시endl; break;
case 36: four=four+1; cout■ = 1칸 앞으로endl; break;
case 42: four=four+2; cout■ = ●와 위치바꾸기endl; temp=four; four=two; two=temp; break;
case 48: four=four-8; cout■ = 8칸 뒤로endl; break;
case 49: four=0; cout■ = 첨부터 다시endl; break;
}
return four;
}/* 게임 메인 함수 */
int main(void)
{
int o,t,tt,f;
int own=0, two=0, three=0, four=0;
cout \t 주사위 굴리기 게임 endl endl endl;
cout \t ★ = own endl;
cout \t ● = two endl;
cout \t ◆ = three endl;
cout \t ■ = four endl endl;
/* do - while 구간 */
do
{
srand((int)time(null));//현재 시간을 이용해서 랜덤숫자 설정
gotoxy(15,14); cout 주사위를 굴리시려면 엔터를 눌러주세요. endl;
gotoxy(15,15); cout 50칸을 먼저 이동한사람이 승리합니다 endl;
getchar();
system(cls);
o=rand()%6+1;own=own+o;//사용자 주사위
t=rand()%6+1; two=two+t;//2번컴퓨터 주사위
tt=rand()%6+1; three=three+tt;//3번컴퓨터 주사위
f=rand()%6+1; four=four+f;//4번컴퓨터 주사위/* 게임 끝 조건 */
if(own=50 || two=50 || three=50 || four=50) { break; }/*함수 호출 구간*/
gotoxy(1,8); p(own, three);
gotoxy(1,9); pp(two, own);
gotoxy(1,10); ppp(three, four);
gotoxy(1,11); pppp(four, two);/* 게임 플레이어 정보 출력 */
gotoxy(1,0); cout \t 주사위 굴리기 게임;
gotoxy(1,3); cout \t ★ = own;
gotoxy(1,4); cout \t ● = two;
gotoxy(1,5); cout \t ◆ = three;
gotoxy(1,6); cout \t ■ = four;
}while(1);/* 최종 게임 스코어 정보 출력 */
system(cls);
cout endl endl endl;
cout \t\t ★ = own endl;
cout \t\t ● = two endl;
cout \t\t ◆ = three endl;
cout \t\t ■ = four endl endl endl;
cout \t\t 각 플레이어의 점수 현황입니다. endl;
cout \t\t 엔터를 누르시면 창이 종료됩니다. endl endl endl;
getchar();
return 0;
}