c语言结构数组

[复制链接]
查看11 | 回复3 | 2011-4-10 13:49:35 | 显示全部楼层 |阅读模式
编写一个学生信息的结构数组,包含学号,身高,体重
输入1,2,3分别按照学号,身高,体重排序
麻烦帮我看看哪里出错了
#include "stdafx.h"
#include
struct Student
{int num;

float hgt;
float wgt;
};
int main(int argc, char* argv[])
{
struct Student stu[5]={{20801,175,60},{20903,183.2,71.3},{20705,169.1,66.4},
{20841,185.6,78},{20735,192,86.5}};

struct Student temp;
const int n=5;
int x,i,j,k;
cout>x;
switch(x)
{
case 1:
coutstu[k].num)

k=j;

temp=stu[k];stu[k]=stu;stu=temp;
}
for(i=0,istu[k].hgt)

k=j;

temp=stu[k];stu[k]=stu;stu=temp;
}
for(i=0,istu[k].wgt)

k=j;

temp=stu[k];stu[k]=stu;stu=temp;
}
for(i=0,i<n;i++)
cout<<"the order is: "<<stu.num,stu.hgt,stu.wgt<<endl;
break;
}

return 0;
}

回复

使用道具 举报

千问 | 2011-4-10 13:49:35 | 显示全部楼层
先帮你指出错误:1,struct Student stu[5]={{20801,175,60},{20903,183.2,71.3},{20705,169.1,66.4}, {20841,185.6,78},{20735,192,86.5}};//71.3这样的数默认以double类型保存,所以如果是float类型的话需要用71.3f这样的方式表示。2, for(i=0,i<n;i++) //‘,’改成‘;’ cout<<"the order is: "<<stu.num,stu.hgt,stu.wgt<<endl; //使用cout需要加上std::名字空间,或在文件开头统一使用using namespace
回复

使用道具 举报

千问 | 2011-4-10 13:49:35 | 显示全部楼层
// #include "stdafx.h"#include struct Student{int num;float hgt;float wgt;};int main(int argc, char* argv[]){ struct Student stu[5]={
{20801,
回复

使用道具 举报

千问 | 2011-4-10 13:49:35 | 显示全部楼层
太浮渣了。。。。
回复

使用道具 举报

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

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行