변수의 값이 저장이 않되네요;;
퐁당
질문 제목 : 변수의 값이 저장이 않되네요;;질문 요약 :포인터와 메모리 어드레스를 사용해서 함수호출을 했는데 변수의 값이 변하지 않네요;;질문 내용 :
#include stdio.h
#include stdlib.h
#include time.h
int wi();
void work();
void mushroom();
void rest();
main()
{
static unsigned int homi;
static unsigned int doki;
static unsigned int mjang;
static unsigned int gok;
static unsigned int hlight;
static unsigned int fipole;
static unsigned int hammer;
static unsigned int welder;
static unsigned int sap;
static unsigned int fdate;
static unsigned int pratice;
static unsigned int ground;
static int money;
static unsigned int fmoney;
static unsigned int date;
static int hp;
static char name[80];
int i4=0;
if(date==0)
{
int i1=0;
int i2=2;
int i3=0;
printf(===============================================================================);
printf(\n돈벌기 타이쿤 ver 0.1);
printf(\n===============================================================================);
while(i1==0)
{
printf(\n[1]처음 시작하기 \t [2]불러오기\n);
scanf(%d,&i1);
if(i1!=1&&i1!=2)
i1=wi(i1,0);
if(i1==2)
{
printf(\n미준비 서비스입니다.);
i1=0;
}
}
while(i1==1)
{
printf(\n===============================================================================);
printf(\n[1] 처음 시작하기를 선택하셨습니다.);
printf(\n===============================================================================);
while(i2==2)
{
printf(\n시작시 사용할 이름을 쓰시오 :);
scanf(%s,&name);
printf(\n%s가 맞습니까?,name);
printf(\n[1]예 [2]아니오\n);
scanf(%d,&i2);
if(i2!=1&&i2!=2)
i2=wi(i2,2);
}
printf(이름이 %s로 결정되었습니다.,name);
while(i3==0)
{
printf(\n===============================================================================);
printf(\n난이도를 선택하십시오.);
printf(\n[1]쉬움 [2]보통 [3]어려움 [4]Help\n);
scanf(%d,&i3);
if(i3!=1&&i3!=2&&i3!=3&&i3!=4)
i3=wi(i3,0);
if(i3==1)
{
printf(\n[1]쉬움 난이도가 선택되었습니다.);
fdate=100;
fmoney=10000;
}
else if(i3==2)
{
printf(\n[2]보통 난이도가 선택되었습니다.);
fdate=80;
fmoney=12000;
}
else if(i3==3)
{
printf(\n[3]어려움 난이도가 선택되었습니다.);
fdate=60;
fmoney=14000;
}
else if(i3==4)
{
printf(\n===============================================================================);
printf(\n[1]쉬움: 기한 일수 100일, 목표 금액 10,000원\n);
printf(\n[2]보통: 기한 일수 80일, 목표 금액 12,000원\n);
printf(\n[3]어려움: 기한 일수 60일, 목표 금액 14,000원);
i3=0;
}
}
i1=0;
date=1;
}
}
while(i4==0)
{
printf(\n===============================================================================\n);
printf(\t\t\t\t%d 일 %d 현재 금액 %d 남은 기간 %d 목표 금액,date,money,fdate,fmoney);
printf(「1」호미 %d 개 「2」도끼 %d 개 「3」전기톱 %d 개 「4」면장갑 %d 개\n「5」곡괭이 %d 개 「6」헤드 라이트 %d 개 「7」낚시대 %d 개 「8」망치 %d 개\n「9」용접기 %d 개 「10」삽 %d 개,homi,doki,mjang,gok,hlight,fipole,hammer,welder,sap);
printf(\n===============================================================================\n);
printf([1]일하러 가기 [2]물건 사기 [3]내 정보 살펴보기 [4]세이브 [5]쉬기 [6]도움말\n);
scanf(%d,&i4);
switch(i4)
{
case 1: work(&pratice,&hp,homi,&money,ground);
break;
case 5: rest(&date,&hp);
break;
}
i4=0;
}
return 0;
}
int wi(wrongp,truep)
int wrongp,truep;
{
printf(\n잘못된 입력입니다.);
wrongp=truep;
return wrongp;
}
void work(pratice,hp,homi,money,ground)
int *pratice,*hp,homi,*money,ground;
{
int work1=0;
while(*pratice10&&work1==0)
{
printf(\n===============================================================================\n);
printf([1]ntf([1]버섯 캐기 [2]벌목 하기 [3]농사 짓기\n);
scanf(%d,&work1);
if(work1!=1&&work1!=2&&work1!=3&&work1!=4)
work1=wi(work1,0);
if(work1==1&&*hp30)
{
printf([1]버섯 캐기를 선택하셨습니다.);
mushroom(homi,&hp,ground,&pratice,&money);
}
}
}
void mushroom(int homi,int *hp,int ground,int *pratice,int *money)
{
int getmoney,pluspratice;
srand(time(NULL));
getmoney=rand()%31+5;
*money=+getmoney;
*hp=-30;
pluspratice=rand()%11+3;
*pratice+=pluspratice;
printf(%d의 금액을 얻었고 30의 체력이 소모되었으며 %d만큼의 숙련도가 올라갔습니다.,getmoney,pluspratice);
}
void rest(int *date,int *hp)
{
*date++;
*hp=100;
}
색을 칠한 부분 중에서 메인 함수 및 work함수에 있는 색칠한 부분은 함수를 호출한 부분입니다. 어드레스 연산자를 사용했지요;; 그리고 함수 호출을 했는데 값이 변하지 않네요;;(예를 들어 mushroom 함수에서 money 변수 값이 변했는데 메인 함수로 되돌아가면 변하지 않고 rest 함수에서 date 변수 값이 변했는데 변하지 않네요;;
-
징징몬
오오오;;;
감사합니다 ㅠ.ㅠ 되네요;; -
레나
흠...컴파일 되는진 모르겠지만
*money += getmoney
(*date)++
이렇게 바꿔보세요 -
새늘
아마 될겁니다;; 전 visual c++ 6.0 쓰지만요 ㅇㅅㅇ;;
-
매1혻적
이거 복사해서 컴파일하면 되는건가요... VS2005 쓰는뎅 ;;