主题:高手帮帮忙,我这个程序那里错了,怎么最后得分输出会是 0 呢?
#include<iostream.h>
#include<iomanip.h>
double cj[3][5];
char name[3][10];
double p[3];
void input_data( );
void max_min();
void sort( );
void main()
{
input_data();
max_min( );
sort();
}
void input_data()
{
int i,j;
for(i=0;i<3;i++)
{
{
cout<<"输入第 "<<i+1<<" 个选手的姓名:"<<endl;
cin>>name[i];
cout<<"请输入第 "<<i+1<<" 个选手各个评委给分:"<<endl;
}
for(j=0;j<5;j++)
cin>>cj[i][j];
}
}
void max_min()
{
int i ,j;
double sum=0,v[3],p[3];
double maxs,mins,max[3],min[3];
for (i=0;i<3;i++)
{
for (j=0;j<5;j++)
sum+=cj[i][j];
v[i]=sum;
sum=0;
}
for (i=0;i<3;i++)
{
maxs=cj[i][0]; mins=cj[i][0];
for (j=1;j<5;j++)
{
if (maxs < cj[i][j])
maxs=cj[i][j];
if (mins > cj[i][j])
mins=cj[i][j];
}
max[i]=maxs;
min[i]=mins;
}
for (i=0;i<3;i++)
p[i]=(float) (v[i]-max[i]-min[i])/3;
cout<<endl<<endl<<endl;
cout<<" 各位选手比赛的基本情况如下:"<<endl;
for (i=0;i<3;i++)
{
// cout<<" ____________________________________________________________________"<<endl;
cout<<"| "<<i+1<<" 号选手: "<<"| 最高分: "<<setiosflags(ios::fixed)<<setprecision(2)<<max[i]<<" | 最低分: "<<setiosflags(ios::fixed)<<setprecision(2)<<min[i]<<" | 最后得分: "<<setiosflags(ios::fixed)<<setprecision(2)<<p[i]<<" |"<<endl;
// cout<<"|______________"<<"|________________"<<"|________________|___________________|"<<endl;
}
cout<<endl<<endl<<endl<<endl;
}
void sort()
{
int i ,j;
double t;
for (i=0;i<3;i++)
{
for (j=0;j<3-i;j++)
if (p[j]>p[j+1])
{
t=p[j];p[j]=p[j+1];p[j+1]=t;
}
}
cout<<" 最后排名情况如下:"<<endl;
for (i=0;i<3;i++)
{
// cout<<" __________________________________________________________"<<endl;
[b]cout<<"| "<<i+1<<" 号选手: "<<"| 姓名: "<<name[i]<<" | 最后得分: "<<setiosflags(ios::fixed)<<setprecision(2)<<p[i]<<" |"<<endl;[/b] // cout<<"| "<<"| "<<" | |"<<endl;
}
}
[b][/b]
#include<iomanip.h>
double cj[3][5];
char name[3][10];
double p[3];
void input_data( );
void max_min();
void sort( );
void main()
{
input_data();
max_min( );
sort();
}
void input_data()
{
int i,j;
for(i=0;i<3;i++)
{
{
cout<<"输入第 "<<i+1<<" 个选手的姓名:"<<endl;
cin>>name[i];
cout<<"请输入第 "<<i+1<<" 个选手各个评委给分:"<<endl;
}
for(j=0;j<5;j++)
cin>>cj[i][j];
}
}
void max_min()
{
int i ,j;
double sum=0,v[3],p[3];
double maxs,mins,max[3],min[3];
for (i=0;i<3;i++)
{
for (j=0;j<5;j++)
sum+=cj[i][j];
v[i]=sum;
sum=0;
}
for (i=0;i<3;i++)
{
maxs=cj[i][0]; mins=cj[i][0];
for (j=1;j<5;j++)
{
if (maxs < cj[i][j])
maxs=cj[i][j];
if (mins > cj[i][j])
mins=cj[i][j];
}
max[i]=maxs;
min[i]=mins;
}
for (i=0;i<3;i++)
p[i]=(float) (v[i]-max[i]-min[i])/3;
cout<<endl<<endl<<endl;
cout<<" 各位选手比赛的基本情况如下:"<<endl;
for (i=0;i<3;i++)
{
// cout<<" ____________________________________________________________________"<<endl;
cout<<"| "<<i+1<<" 号选手: "<<"| 最高分: "<<setiosflags(ios::fixed)<<setprecision(2)<<max[i]<<" | 最低分: "<<setiosflags(ios::fixed)<<setprecision(2)<<min[i]<<" | 最后得分: "<<setiosflags(ios::fixed)<<setprecision(2)<<p[i]<<" |"<<endl;
// cout<<"|______________"<<"|________________"<<"|________________|___________________|"<<endl;
}
cout<<endl<<endl<<endl<<endl;
}
void sort()
{
int i ,j;
double t;
for (i=0;i<3;i++)
{
for (j=0;j<3-i;j++)
if (p[j]>p[j+1])
{
t=p[j];p[j]=p[j+1];p[j+1]=t;
}
}
cout<<" 最后排名情况如下:"<<endl;
for (i=0;i<3;i++)
{
// cout<<" __________________________________________________________"<<endl;
[b]cout<<"| "<<i+1<<" 号选手: "<<"| 姓名: "<<name[i]<<" | 最后得分: "<<setiosflags(ios::fixed)<<setprecision(2)<<p[i]<<" |"<<endl;[/b] // cout<<"| "<<"| "<<" | |"<<endl;
}
}
[b][/b]