c语言问题,求高手帮忙解答

/*
.某商场某天的商品销售情况如下表所示,编程计算每种商品的销售额及所有商品的总销售额,并按表格形式输出。
commodity number unit price sale
television 5 5000
refrigerator 8 2200
washing machine 10 1100
water heater 3 860
microwave oven 6 800
*/
#include<stdio.h>
void main()
{
char commodity[5]={"television","refrigerator","washing machine","water heater","microwave oven"];
int number[5]={5,8,10,3,6};
int unit_price[5]={5000,2200,1100,860,800};
long sale[5];
for(int i=0;i++;i<5)
{
sale[i]=number[i]*unit_price[i];
}
printf("commodity number unit price sale");
for(int i=0;i++;i<5)
{
printf("%10c,%10d,%10d,%10ld",commodity[i],number[i],unit_price[i],sale[i];
}
怎么改啊

#include<stdio.h>
void main()
{
char *commodity[5]={"television","refrigerator","washing machine","water heater","microwave oven"};//有错
int number[5]={5,8,10,3,6};
int unit_price[5]={5000,2200,1100,860,800};
long sale[5];
for(int i=0;i<5;i++)//有错
{
sale[i]=number[i]*unit_price[i];
}
printf("commodity\t number unit \t price\t sale\n");
for(int i=0;i<5;i++)//有错
{
printf("%s,%10d,%10d,%10ld\n",*(commodity+i),number[i],unit_price[i],sale[i]);//有错
}
}
温馨提示:内容为网友见解,仅供参考
第1个回答  2010-11-08
/*
.某商场某天的商品销售情况如下表所示,编程计算每种商品的销售额及所有商品的总销售额,并按表格形式输出。
commodity number unit_price sale
television 5 5000
refrigerator 8 2200
washing machine 10 1100
water heater 3 860
microwave oven 6 800
*/
#include<stdio.h>
void main()
{
char *commodity[5]={"television","refrigerator","washing machine","water heater","microwave oven"};
int number[5]={5,8,10,3,6};
int unit_price[5]={5000,2200,1100,860,800};
long sale[5];
for(int i=0;i<5;i++)
{
sale[i]=number[i]*unit_price[i];
}
printf("commodity\t\tnumber\t\tunit_price\tsale\n\n");
for(i=0;i<5;i++)
printf("%s\t\t%d\t\t%d\t\t%d\n",commodity[i],number[i],unit_price[i],sale[i]);
}
相似回答