编译和连接都没错,输入数据时报错。。。。。

[复制链接]
查看11 | 回复5 | 2010-12-23 12:02:30 | 显示全部楼层 |阅读模式
#include"stdio.h"
struct student
{
char name;
float code[3];
float total;
};
void main()
{
int i,j;
float total1[3]={0,0,0};
float avg[3]={0,0,0};
struct student stu[3];
printf("输入信息:");
for(i=0;i<3;i++)
{
for(stu.total=0,j=0;j<3;j++)
{
scanf("%f",stu.code[j]);
stu.total+=stu.code[j];
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{

total1=stu[j].code;
}
avg=total1/3.0;
}
printf("输出信息:\n");

for(i=0;i<3;i++)
{

printf("%4s %3f %3f %3f %3f",stu.name,&stu.code[0],&stu.code[1],&stu.code[2],&stu.total);
}
printf("三门课各自的平均分:");
for(i=0;i<3;i++)
{
printf("%f\n",avg);
}
}
不好意思只有这么都分了

回复

使用道具 举报

千问 | 2010-12-23 12:02:30 | 显示全部楼层
#include"stdio.h"struct student{ char name[10];//定义成字符数组 float code[3]; float total;};void main(){ int i,j; float total1[3]={0,0,0}; float avg[3]={0,0,0}; struct student stu[3]; printf("输入信息:"); for(i=0;i<3;i++) {printf("输入名字:");
//没有名字录入,却输入scanf("%s",stu.name);for(stu.tota
回复

使用道具 举报

千问 | 2010-12-23 12:02:30 | 显示全部楼层
for (int i = 0; i <= 9; i++) {
jbtNumber = new JButton(""+i); // jbtNumber.setText(""+i); // ""+i 使i转化为字符 }因为你没new就使用,所以报空指针。改成如上即可。 JButton[] jbtN
回复

使用道具 举报

千问 | 2010-12-23 12:02:30 | 显示全部楼层
#include"stdio.h"struct student{ char name[20]; float code[3]; float total;};int main(){ int i,j; float total1[3]={0,0,0}; float avg[3]={0,0,0}; struct stud
回复

使用道具 举报

千问 | 2010-12-23 12:02:30 | 显示全部楼层
三点第一:输入输出有问题,输入时,取变量的地址,输出时取变量的值;因此scanf("%f",stu.code[j]); 加取地址符 改为:scanf("%f",&stu.code[j]);printf("%4s %3f %3f %3f %3f",stu.name,&stu.code[0],&stu.code[
回复

使用道具 举报

千问 | 2010-12-23 12:02:30 | 显示全部楼层
#include"stdio.h"struct student{ char name[5]; float code[3]; float total;};int main(){ int i,j; float total1[3]={0,0,0}; float avg[3]={0,0,0}; struct stude
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行