파일도 같이 올렸어용~ㅋ
라와
질문 제목 : 가계부 코드입니다~질문 요약 :실행은 되는데요;; 저기 빨간색 부분에서 머가 잘못되었는지;;
code같은 거끼리 합산하구 입금 총액(plus), 출금 총액(minus) 계산했는데;;
시험삼아 code가 1인것만 합산한 변수 a만 출력해보았더니 이상한 값이 나오네요;;
머가 잘못된 걸까요,ㅠ;;? (처음에 답변해주신대로 &를 뺐는데도 이상한 값이 나오네요,ㅠ질문 내용 :
#include stdio.h
struct std{
int day[4];
char number;
int code;
int money;
} ;
void sort(struct std *temp, int no)
{
int i, j ;
for(i=0;ino;i++)
for(j=i+1;jno;j++)
{
if(temp[i].day[2]temp[j].day[2])
temp[j].day[3]++;
else if(temp[i].day[2]temp[j].day[2])
temp[i].day[3]++;
else if(temp[i].day[2]==temp[j].day[2])
{
if(temp[i].codetemp[j].code)
temp[i].day[3]++;
else
temp[j].day[3]++;
}
}
}
void main()
{
static struct std table[100];
FILE * in;
int i, j, cnt, a, b, c, d, e, f, plus, minus, total;
in=fopen(input.txt, rt);
for(i=0; i12; i++)
{
for(j=0;j3;j++)
{
fscanf(in, %2d,&table[i].day[j]);
}
table[i].day[3]=1;
fscanf(in,%c,&table[i].number);
fscanf(in,%2d,&table[i].code);
fscanf(in,%8d,&table[i].money);
}
fclose(in);
cnt=i;
sort(table,cnt);
for(i=0;icnt;i++)
{
if(table[i].code==01)
a+=table[i].money;
else if(table[i].code==02)
b+=table[i].money;
else if(table[i].code==03)
c+=table[i].money;
else if(table[i].code==04)
d+=table[i].money;
else if(table[i].code==05)
e+=table[i].money;
else
f+=table[i].money;
}
for(i=0;icnt;i++)
{ if(table[i].number==)
plus+=table[i].money;
else
minus+=table[i].money;
}
total=plus-minus;
printf(입금 날짜 출금\n);
for(j=1; jcnt; j++)
{
for(i=0; icnt; i++)
{
if(table[i].day[3]==j)
{
if(table[i].number==)
{ printf(%3d, table[i].money);
printf( %d년, table[i].day[0]);
printf(%d월, table[i].day[1]);
printf(%d일, table[i].day[2]);
printf(\n);
}
else
{
printf(%10d년, table[i].day[0]);
printf(%d월, table[i].day[1]);
printf(%d일, table[i].day[2]);
printf(%3d, table[i].money);
printf(\n);
}
}
}
}
printf(%d\n,a);
}