/* global variables */
int maxRecord=0;
time_t ltime;
char buf[128];
/* unix time
time(<ime);
printf("%s",ctime(<ime));
*/
main(){
char option;
initialize();
_strdate(buf); /* _strtime(buf)
will display the local time */
do{
printf("\tMainmenu \n\t%s\n",buf);
printf("1. Make payment\n");
printf("2. Enter Purchase\n");
printf("3. View Record\n");
printf("q. Quit\n");
option=getchar();
fflush(stdin);
switch(option){
case '1': printf("\tMAKE PAYMENT\n");
paymentRec();
break;
case '2': printf("\tENTER PURCHASE
DETAILS\n");
enterRec();
break;
case '3': printf("\tVIEW RECORDS\n");
viewRec();
break;
case 'Q': option='q';
break;
}
}while(option!='q');
}
initialize(){
int i;
for(i=0;i<100;i++){
cust[i].name[0]=' ';
cust[i].purchaseDate.dd=0;
cust[i].purchaseDate.mm=0;
cust[i].purchaseDate.yy=0;
cust[i].amount=0.0;
cust[i].paymentDate.dd=0;
cust[i].paymentDate.mm=0;
cust[i].paymentDate.yy=0;
}
}
enterRec(){
char arrName[80];
char confirmYN;
int day,month,year, i=maxRecord;
float amt;
printf("Please enter account
Name:");
gets(arrName);
fflush(stdin);
printf("Enter Purchase date(dd/mm/yy):");
scanf("%d/%d/%d",&day,&month,&year);
fflush(stdin);
printf("Enter Purchase Amount:");
scanf("%f",&amt);
fflush(stdin);
printf("Press 'y' to confirm
entry:");
if((confirmYN=getchar()) !=
'y'){
printf("Records not updated!\n");
}
else{
strcpy(cust[i].name,arrName);
cust[i].purchaseDate.dd=day;
cust[i].purchaseDate.mm=month;
cust[i].purchaseDate.yy=year;
cust[i].amount=amt;
maxRecord++;
}
fflush(stdin);
return 0;
}
viewRec(){
char arrName[80];
int i=0;
printf("Enter name to view:");
gets(arrName);
fflush(stdin);
while(i<=maxRecord){
if(! strcmp(cust[i].name,arrName)){
printf("Name:%s\n",cust[i].name);
printf("Purchase date:%d/%d/%d\tPurchase
balance:%f\n",\
cust[i].purchaseDate.dd,\
cust[i].purchaseDate.mm,\
cust[i].purchaseDate.yy,\
cust[i].amount);
if(cust[i].paymentDate.dd==0)
printf("No Payments
made!\n");
else
printf("Last payment
on:%d/%d/%d\n", \
cust[i].paymentDate.dd,\
cust[i].paymentDate.mm,\
cust[i].paymentDate.yy);
}
i++;
}
}
paymentRec(){
char arrName[80];
int i=0, found=0;
float amt=0.0;
printf("Enter name to make payment:");
gets(arrName);
fflush(stdin);
while(i<=maxRecord){
if(! strcmp(cust[i].name,arrName)){
printf("Name:%s\n",cust[i].name);
printf("Purchase date:%d/%d/%d\tPurchase
balance:%f\n",\
cust[i].purchaseDate.dd,
\
cust[i].purchaseDate.mm,
\
cust[i].purchaseDate.yy,
\
cust[i].amount);
if(cust[i].amount<=0)
printf("Zero Balance!\n");
else{
printf("Enter payment
amount:");
scanf("%f",&amt);
fflush(stdin);
printf("Payment
made on (dd/mm/yy):");
scanf("%d/%d/%d",
\
&cust[i].paymentDate.dd,
\
&cust[i].paymentDate.mm,
\
&cust[i].paymentDate.yy);
fflush(stdin);
cust[i].amount-=amt;
/* validation may be required */
found=1;
}
}
i++;
}
if(found==0)
printf("No such name found!\n");
return 0;
}
This page created with Netscape Navigator Gold (17/9/1999)