*首先合计花费保存有错误 还有就是中途填写时有BUG*/
/*版权信息存属搞笑*/
#include<stdio.h>
#include<dos.h>
#include<dir.h>
/*--------------版权信息------------------*/
void copyright()
{
gotoxy(12, 1);printf("*---------------------------------------------------*");
gotoxy(12, 2);printf("| Money Management System v1.0 |");
gotoxy(12, 3);printf("| Designed By PrOve |");
gotoxy(12, 4);printf("| CopyRight 2005-6-30 |");
gotoxy(12, 5);printf("| HelloWorldCorperation |");
gotoxy(12, 6);printf("*---------------------------------------------------*");
}
/*-----------------End--------------------*/
/*--------------提示信息------------------*/
void tips()
{
gotoxy( 2, 7);printf("*--------------Record--------------*");
gotoxy(40, 7);printf("*---------------List---------------*");
gotoxy(2 ,22);printf("*==================================*");
gotoxy(2 ,23);printf("| Tab:_Next Esc:_Finished&_Quit |");
}
/*----------------End---------------------*/
/*--------------信息列表------------------*/
void litable(int k)
{
gotoxy( 2, 8+3*k);printf("| Date :");
gotoxy(37, 8+3*k);printf("|");
gotoxy( 2, 9+3*k);printf("| Goods :");
gotoxy(37, 9+3*k);printf("|");
gotoxy( 2,10+3*k);printf("| Cost :");
gotoxy(37,10+3*k);printf("|");
gotoxy( 2,11+3*k);printf("*----------------------------------*");
}
/*------------------End-------------------*/
/*----------------退出汇总----------------*/
main()
{
struct date d;
char curdate[11],goods[10],ctrl='/0',/*按键控制*/golist[40][10],/*商品列表*/colist[40][10];/*商品金额列表*/
float sum=0,/*商品总额*/cost; /*商品金额*/
int n=0;/*商品数量*/
int k=0,/*行数控制*/i=0;/*数组下标索引*/
copyright();
win:/*标题标签*/
tips();
list:/*列表标签*/
litable(k);
/*------------------显示当天日期-------------------*/
getdate(&d);
sprintf(curdate,"%4d-%02d-%02d",d.da_year,d.da_mon,d.da_day);
gotoxy(13,8+3*k);printf("%s",curdate);
gotoxy(44,8+3*k);printf("%s",curdate);
/*----------------------End------------------------*/
/*-------------------输入购买的货物----------------*/
quit_sum(sum,curdate,n,golist,colist);
gotoxy(13,9+3*k);scanf("%s",goods);
sprintf(golist[i],"%s",goods);
gotoxy(57,8+3*k);printf("%s",goods);
/*----------------------End------------------------*/
/*-------------------输入花费的金额----------------*/
quit_sum(sum,curdate,n,golist,colist);
while(1)
{
gotoxy(13,9+3*k);
if(((ctrl=getch())==9)||(ctrl=='/r'))
{
gotoxy(13,10+3*k);scanf("%f",&cost);
sprintf(colist[i++],"%.2f",cost);
gotoxy(64,8+3*k);printf("%.2f",cost);
break;
}
}
sum+=cost;
gotoxy(41,8+3*k);printf("%d).",++n);
k++;
if(k>3)
{
clrscr();
k=0;
goto win;
}
/*----------------------End------------------------*/
goto list;
}
void quit_sum(float sum,char curdate[],int n,char golist[][10],char colist[][10])
{
FILE *fw=fopen("MoneyMS","at+");
char esc=getch();
char *curdir,path[MAXPATH];/*当前路径*/
int i;
if(esc==27)/*Esc键退出*/
{
clrscr();
gotoxy(3,1);printf("Date: %s",curdate);
gotoxy(2,2);printf("*---------------List---------------*");
for(i=0;i<n;i++)
{
gotoxy(3,3+i);printf("%s",golist[i]);
gotoxy(11,3+i);printf("%s",colist[i]);
}
inputf(fw,golist,colist,n,sum);
gotoxy(2,3+i);printf("*----------------------------------*");
gotoxy(3,4+i);printf("Total :%.2f yuan",sum);
curdir=path;
curdir[0]='A'+getdisk();
getcurdir(0,curdir+3);
gotoxy(3,7+i);printf("All the information has been saved here:");/*输出信息存储路径*/
gotoxy(3,8+i);printf("%s",path);
getch();
exit(1);
}
}
/*------------------End-------------------*/
/*--------------信息写入文件--------------*/
inputf(FILE *fw,char golist[][10],char colist[][10],int n,float sum)
{
int i;
if((fw=fopen("MoneyMS","wb+"))==NULL)
{
clrscr();
printf("Error!Cannot open file!");
getch();
exit(0);
}
for(i=0;i<n;i++)
{
fprintf(fw,"%s/t%s/n",golist[i],colist[i]);
}
fprintf(fw,"sum:%.2f",sum);
}
/*-----------------End---------------------*/