#include<stdio.h>
#include<malloc.h>
typedef 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(pay<sum)
printf("付款金额不足,应付金额:%.2f\n",sum)
else
break
}
printf("实付金额:%.2f。应付金额:%.2f。找零:知纤段%.2f\n",pay,sum,pay-sum)
return 0
}
float getSum(SP *spHead)//获取总金额
{
float sum=0
while(spHead->next!=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
else
spTail->next=spNew
spTail=spNew
}
}while(spNew->price!=0)
free(spNew)
return spTail
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)