这个用C语言怎么写?麻烦写下代码,谢谢!
1个回答
展开全部
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>
struct Commodity{
char szName[32];
float fPrice;
int iCount;
};
#define LENGTH 5
int main()
{
int i=0, isVIP = 0;
float fSum = 0.0 ;
Commodity obComs[LENGTH];
memset(obComs, 0, sizeof(Commodity)*LENGTH);
strcpy(obComs[0].szName, "Basketball");
obComs[0].fPrice = 120;
obComs[0].iCount = 1;
strcpy(obComs[1].szName, "Football");
obComs[1].fPrice = 120;
obComs[1].iCount = 1;
strcpy(obComs[2].szName, "Volleyball");
obComs[2].fPrice = 85.0;
obComs[2].iCount = 1;
strcpy(obComs[3].szName, "Tennis Racket");
obComs[3].fPrice = 65.0;
obComs[3].iCount = 1;
strcpy(obComs[4].szName, "Table Tennis Bat");
obComs[4].fPrice = 35.0;
obComs[4].iCount = 1;
printf("Commodity Name\t\tCount\tUnit Price\tTotal Amount\n");
for (i=0; i<LENGTH; i++)
{
fSum += obComs[i].iCount*obComs[i].fPrice;
printf("%s\t\t%d\t%f\t%f\n", obComs[i].szName, obComs[i].iCount,
obComs[i].fPrice,obComs[i].iCount*obComs[i].fPrice);
}
if (isVIP == 1){
fSum *= 0.9f;
}
printf("Total Amount is %f\n", fSum);
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询