변수의 값이 저장이 않되네요;;
피네
질문 제목 : 변수의 값이 저장이 않되네요;;질문 요약 :포인터와 메모리 어드레스를 사용해서 함수호출을 했는데 변수의 값이 변하지 않네요;;질문 내용 :
#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 변수 값이 변했는데 변하지 않네요;;
-
소희 2025-06-16
오오오;;;
감사합니다 ㅠ.ㅠ 되네요;; -
거북이 2025-06-16
흠...컴파일 되는진 모르겠지만
*money += getmoney
(*date)++
이렇게 바꿔보세요 -
망고 2025-06-16
아마 될겁니다;; 전 visual c++ 6.0 쓰지만요 ㅇㅅㅇ;;
-
지음 2025-06-16
이거 복사해서 컴파일하면 되는건가요... VS2005 쓰는뎅 ;;
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2703038 | 솔루션 빌드를 하고 실행하는거랑 (5) | 홀림길 | 2025-07-28 |
2703014 | void *fuction(int a) 이런 함수 질문좀요 (3) | 박애교 | 2025-07-28 |
2702932 | 기본 구조체 인데 잘 모르겠네요.ㅠㅠ | 한국녀 | 2025-07-27 |
2702877 | DVD대여프로그램인데요~ 도와주세요!! | 하늘 | 2025-07-27 |
2702850 | enum인데 해석이 안됩니다.. (1) | 수국 | 2025-07-26 |
2702822 | 가우스 소거법좀 부탁드립니다. | 큰힘 | 2025-07-26 |
2702797 | system("mode con: .. ); 명령어 vs2005에서는.. (1) | 콩알눈 | 2025-07-26 |
2702775 | % 연산자, / 연산자 관련질문 | 솔잎 | 2025-07-26 |
2702743 | Linux message queue를 이용한 방법에서 msgrcv | 뚜야 | 2025-07-25 |
2702661 | 동적으로 3개씩 할당되는 배열 (7) | 별빛 | 2025-07-25 |
2702638 | 문제해결좀 (1) | 개굴츼 | 2025-07-24 |
2702495 | mfc edit control 공백체크 (4) | 분홍이 | 2025-07-23 |
2702465 | 이 함수호출에서 뭐가 잘못됬죠 ?ㅠ | 미즈 | 2025-07-23 |
2702438 | C언어에서 Addr이 뭔가요? (6) | 밝은빛누리예 | 2025-07-23 |
2702384 | 흠.. 피보나치 수열을... for문으로 만들었는데요....ㅠㅠ;; (1) | 계획자 | 2025-07-22 |
2702354 | c언어 하나더 질문드리겠습니다^^ | 유키 | 2025-07-22 |
2702323 | 배열 최빈값 구하는 소스 좀 갈켜주셈. | PrinceSs | 2025-07-22 |
2702296 | 오류좀 찾아주세요! 스왑함수 (1) | 지우 | 2025-07-21 |
2702232 | 글씨를 검은색, 바탕을 하얀색으로 하는방법좀 가르쳐주세요 !! | 놓아주세요 | 2025-07-21 |
2702205 | for문 중첩ㅠㅠ (2) | 한뎃집 | 2025-07-21 |