c++小问题...请帮一下忙

来源:百度知道 编辑:UC知道 时间:2024/05/22 01:29:13
// test019.cpp : Defines the entry point for the console application.
//有N个学生,每个学生的信息包括学号、性别、姓名、四门课的成绩,从键盘上输入N个学生的
//信息,要求输出总平均成绩最高的学生信息,包括学号、性别、姓名和平均成绩.

#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;

int average (int a,int b,int c)
{int faver=(a+b+c)/3;
return faver;
}

int main(int argc, char* argv[])
{
struct
{
char name[10];
int num;
char sex[8];
int x;
int y;
int z;
} st[3];
for (int i=0;i<3;++i)
{
cout<<"please enter the name:";
scanf ("%s\n",st[i].name);
cout<<"please enter the num:";
//cin>>st[i].num<<endl; //为什么用cin>>输入就出错了?
cout<<"please enter the sex:";
// cin>>st[i].sex<<endl;
cout<<"please enter the x'mar

说实话...不是打击你,这是我见过写的最烂的程序了
cin后面能接endl;吗?
结构体在函数外部定义.
一个同名变量的定义竟然定义了3次
最不能容忍的是把C和C++的输入输出混合使用...
虽然错误都改了,但是我估计你的算法也有问题,把基础好好学扎实点吧

#include <string>
#include <iostream>
using namespace std;

int average (int a,int b,int c)
{int faver=(a+b+c)/3;
return faver;
}
struct
{
char name[10];
int num;
char sex[8];
int x;
int y;
int z;
} st[3];
int main(int argc, char* argv[])
{

for (int i=0;i<3;++i)
{
cout<<"please enter the name:";
cin >> st[i].name;
cout<<"please enter the num:";
cin>>st[i].num;
cout<<"please enter the sex:";
cin>>st[i].sex;
cout<<"please enter the x'marks:";
cin>>st[i].x;
cout<<"please enter the y'marks:";