新鲜出炉,还有些BUG,可以自行修改。
#include
int main()
{
double rental;//rental销售总额
double pri[5]={2.46,4.95,9.12,4.35,6.66};//pri[]零售价格
int i,num[5],count[5];//num[]名字,sale[]销售数量
for (i=1;i<6;i++)
{
printf ("输入第%d种商品名字和销售量:\n",i);
scanf ("%d %d",&num[i],&count[i]);//无法限制用户输入数据类型,可产生bug
printf ("商品名字:%d,价格:%f,销售量:%d\n",num[i],pri[i],count[i]);//可注释
rental += pri[i]*count[i];//+=
}
printf ("销售总额是%f\n",rental);
}
#include
struct sp
{
char name[10]; //名称数自己定
float price;
int num;
float sum;
}sp[5];
float total=0;
int main()
{
int i;
float calc(float sum1,float sum2, float sum3, float sum4, float sum5);
void output();
for(i=0;i++;i<5)
{
printf("请输入第%d种商品的名称,单价,数量:\n",i);
gets(sp[i].name);
scanf("%f",&sp[i].price);
scanf("%d",&sp[i].num);
sp[i].sum=price*num;
output();
printf("%f\n",calc(sp[0].sum,sp[1].sum,sp[2].sum,sp[3].sum,sp[4].sum));
}
float calc(float sum1,float sum2, float sum3, float sum4, float sum5)
{
total=sum1+sum2+sum3+sum4+sum5;
return total;
}
void output()
{
int i;
for(i=0;i++;i<5)
{
puts(sp[i].name);
printf("\n%f\n",sp[i].price);
printf("%d\n",sp[i].num);
printf("%f\n",sp[i].sum);
}
}
顶楼上
恩恩恩恩恩恩恩,楼上对