请问,下面程序是哪里出问题了呢?输入数据后,一按回车就出问题。 感激不尽... 5
#include<stdio.h>structgoods{longnum;charname[20];floatprice;intnumber;floatsumprice;...
#include<stdio.h>
struct goods
{
long num;
char name[20];
float price;
int number;
float sumprice;
}good[10];
main()
{
int i;
printf("Please input the information of the goods:\n");
for(i=0;i<10;i++)
{
printf("The %d:\n",i+1);
scanf("%ld%s%f%d",&good[i].num,good[i].name,good[i].price,&good[i].number);
good[i].sumprice=good[i].price*good[i].number;
}
printf("Num\tName\tPrice\tNumber\tSumprice\n");
for(i=0;i<10;i++)
{
printf("%ld\t%s\t%.1f\t%d\t.1f\n",good[i].num,good[i].name,good[i].price,good[i].number,good[i].sumprice);
}
} 展开
struct goods
{
long num;
char name[20];
float price;
int number;
float sumprice;
}good[10];
main()
{
int i;
printf("Please input the information of the goods:\n");
for(i=0;i<10;i++)
{
printf("The %d:\n",i+1);
scanf("%ld%s%f%d",&good[i].num,good[i].name,good[i].price,&good[i].number);
good[i].sumprice=good[i].price*good[i].number;
}
printf("Num\tName\tPrice\tNumber\tSumprice\n");
for(i=0;i<10;i++)
{
printf("%ld\t%s\t%.1f\t%d\t.1f\n",good[i].num,good[i].name,good[i].price,good[i].number,good[i].sumprice);
}
} 展开
3个回答
展开全部
#include<stdio.h>
struct goods
{
long num;
char name[20];
float price;
int number;
float sumprice;
}good[10];
main()
{
int i;
printf("Please input the information of the goods:\n");
for(i=0;i<10;i++)
{
printf("The %d:\n",i+1);
scanf("%ld%s%f%d",&good[i].num,&good[i].name,&good[i].price,&good[i].number);/*这边漏掉了 取地址运算符 & */
good[i].sumprice=good[i].price*good[i].number;
}
printf("Num\tName\tPrice\tNumber\tSumprice\n");
for(i=0;i<10;i++)
{
printf("%ld\t%s\t%.1f\t%d\t.1f\n",good[i].num,good[i].name,good[i].price,good[i].number,good[i].sumprice);
}
}
struct goods
{
long num;
char name[20];
float price;
int number;
float sumprice;
}good[10];
main()
{
int i;
printf("Please input the information of the goods:\n");
for(i=0;i<10;i++)
{
printf("The %d:\n",i+1);
scanf("%ld%s%f%d",&good[i].num,&good[i].name,&good[i].price,&good[i].number);/*这边漏掉了 取地址运算符 & */
good[i].sumprice=good[i].price*good[i].number;
}
printf("Num\tName\tPrice\tNumber\tSumprice\n");
for(i=0;i<10;i++)
{
printf("%ld\t%s\t%.1f\t%d\t.1f\n",good[i].num,good[i].name,good[i].price,good[i].number,good[i].sumprice);
}
}
展开全部
亲,scanf("%ld%s%f%d",&good[i].num,good[i].name,good[i].price,&good[i].number);里面
对于price忘了加&了吧。
改为scanf("%ld%s%f%d",&good[i].num,good[i].name,&good[i].price,&good[i].number);
对于price忘了加&了吧。
改为scanf("%ld%s%f%d",&good[i].num,good[i].name,&good[i].price,&good[i].number);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<stdio.h>
struct goods
{
long num;
char name[20];
float price;
int number;
float sumprice;
}good[10];
main()
{
int i;
printf("Please input the information of the goods:\n");
for(i=0;i<10;i++)
{
printf("The %d:\n",i+1);
scanf("%ld%s%f%d",&good[i].num,&good[i].name,&good[i].price,&good[i].number);
good[i].sumprice=good[i].price*good[i].number;
}
printf("Num\tName\tPrice\tNumber\tSumprice\n");
for(i=0;i<10;i++)
{
printf("%ld\t%s\t%.1f\t%d\t%.1f\n",good[i].num,good[i].name,good[i].price,good[i].number,good[i].sumprice);
}
}
struct goods
{
long num;
char name[20];
float price;
int number;
float sumprice;
}good[10];
main()
{
int i;
printf("Please input the information of the goods:\n");
for(i=0;i<10;i++)
{
printf("The %d:\n",i+1);
scanf("%ld%s%f%d",&good[i].num,&good[i].name,&good[i].price,&good[i].number);
good[i].sumprice=good[i].price*good[i].number;
}
printf("Num\tName\tPrice\tNumber\tSumprice\n");
for(i=0;i<10;i++)
{
printf("%ld\t%s\t%.1f\t%d\t%.1f\n",good[i].num,good[i].name,good[i].price,good[i].number,good[i].sumprice);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询