大家帮我看看这个简单的编程吧.

来源:百度知道 编辑:UC知道 时间:2024/06/20 09:53:43
#include<iostream.h>
#include<iomanip.h>
#include<fstream.h>
#include<stdlib.h>

#define FLIN_IN "Football.txt"

struct FootballPlayer
{
char name[40];
float weight;

int highinch;
float hingfoot;
};

float FootballAverages(float []);
void WritePlayer(struct);

int main()
{

FootballPlayer play[3];
FootballPlayer grades[3][3];
float average;
int total;

ifstream input;
input.open(FLIN_IN,ios::in|ios::nocreate);

if(!input)
{
cout<<"\n输入文件无法打开"<<FLIN_IN;
cout<<"\n推出程序再见\n";
exit(1);
}

cout<<"\n程序已经打开继续输入";

char buf[15];

input.getline(buf,15);
total=atoi(buf);

int i,j=0;
for(i=0;i<total;++i)
{

input.getline(pla

这句不对的:
input>>grades[i][j].hingfoot
>>grades[i][j+1].highinch
>>grades[i][j+1+1].weight;

在前面的时候你知道用total=atoi(buf)
后面没注意吧
从文件读进来的是字符串,而highinch和weight不是字符串类型的,也是需要转化以后才能用

不过还有个问题是你的定义也有点问题,看你给的文件数据好像highinch应该是float类型,weight才是int的

grades[3][3]也是没必要的吧,总共就3条数据呀,有play[3]就够了

想求什么平均数呀,文件里面所有的数据都保存在play[3]里面了呀,直接用play[1].highinch这样的办法引用就是了

还是不懂你想干什么。。不好意思……

反正这样读的话就对了
input>>grades[i].hingfoot;
input>>buf;
grades[i].highinch=atof(buf);
input>>buf;
grades[i].weight=atoi(buf);

你先把思路理清楚,到底要干什么,哪一步出了问题,一步步解决,我是只能解决到这里了,后面听不懂