超市收银

#include<stdio.h>
#include<stdlib.h>
#define L sizeof(struct Goods)
struct Goods
{char name[33];
float price;
struct Goods *next;
};
float Total=0;
int main()
{struct Goods *creat();
void print(struct Goods *head);
struct Goods *m;
float k;
printf(“请扫描顾客商品:\n”);
m=creat();
print(m);

scanf("%f",&k);
printf("\n");
printf(“找还您的金额:%.2f\n”,k-Total);
printf(“欢迎您再次光临AR小店\n”);
return 0;
}
struct Goods *creat()
{int n=0,i;
struct Goods *head,*p1,*p2;
head=NULL;
p1=p2=(struct Goods *)malloc(L);
for(i=0;p1->name[i-1]!=’ ‘;i++)
scanf("%c",&p1->name[i]);
scanf("%f",&p1->price);
while(p1->price!=0)
{n++;
if(n==1) head=p1;
else p2->next=p1;
p2=p1;
p1=(struct Goods *)malloc(L);
for(i=0;p1->name[i-1]!=’ ';i++)
scanf("%c",&p1->name[i]);
scanf("%f",&p1->price);
}
p2->next=NULL;
return head;
}

void print(struct Goods *head)
{struct Goods *p=head;
do{
Total+=p->price;
p=p->next;}while(p!=NULL);
printf(“您应付金额:%.2f\n”,Total);
printf(“您实付金额:”);
}

猜你喜欢

转载自blog.csdn.net/AR_Pai/article/details/110943045