写一个超市收银机结账程序

写一个超市收银机结账程序

#include#includetypedef struct sp{float price;//商品价格struct sp *next;//链表指针}SP;SP *inputSP(SP *spHead);//输入价格float getSum(SP *spHead);//获取总金额int main(){float pay,sum;SP *spHead=(SP *)malloc(sizeof(SP));SP *spTail=NULL;// 链表尾指针,本代码用不到,可以删除。spHead->next=NULL;spTail=inputSP(spHead);sum=getSum(spHead);while(1){printf(“请输入付款金额:”);scanf(“%f”,&pay);if(paynext!=NULL){sum=sum+spHead->next->price;spHead=spHead->next;}return sum;}SP *inputSP(SP *spHead){SP *spTail=NULL;SP *spNew=NULL;printf(“输入商品价格:(输入0结束输入)\n”);do{spNew=(SP *)malloc(sizeof(SP));spNew->price=0;spNew->next=NULL;scanf(“%f”,&spNew->price);if(spNew->price!=0){if(spHead->next==NULL)spHead->next=spNew;elsespTail->next=spNew;spTail=spNew;}}while(spNew->price!=0);free(spNew);return spTail;}

一、写一个超市收银机结账程序

#include

#include

int main()

{

int i=0;

double sum=0,price,in;

printf(“请输入价格:\n”);

do{

scanf(“%lf”,&price);

sum+=price;

}

while(price!=0);

printf(“总金额:%.1f\n”,sum);

printf(“请输入收款金额:\n”);

scanf(“%lf”,&in);

printf(“找零金额:%.1f\n”,in-sum);

}

本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。