#include
void get_scores(double *average,double *sum)
{
int chin,math,phys,chem,engl;
cout<<"Enter your score of chin:";
cin>>chin;
cout<<"Enter your score of math:";
cin>>math;
cout<<"Enter your score of phys:";
cin>>phys;
cout<<"Enter your score of chem:";
cin>>chem;
cout<<"Enter your score of engl:";
cin>>engl;
*sum = chin+math+phys+chem+engl;
*average = (*sum)/5;
}
void main()
{
double average;
double sum;
get_scores(&average,&sum);
cout<<"Your average is:"<
//函数参数不是只能传入数据,也可以通过它传出数据。
//当然也可以把多个数据放在一个数组里(如果数据类型一样的话),
//return数组指针
#include
using namespace std;
int get_score(int &average,int &sum)
{
int chin,math,phys,chem,engl;
cout<<"Enter your score of chin:";
cin>>chin;
cout<<"Enter your score of math:";
cin>>math;
cout<<"Enter your score of phys:";
cin>>phys;
cout<<"Enter your score of chem:";
cin>>chem;
cout<<"Enter your score of engl:";
cin>>engl;
average = (chin+math+phys+chem+engl)/5;
sum = chin+math+phys+chem+engl;
}
void main()
{
double average = 0;
double sum = 0;
score = get_scores(average ,sum );
cout<<"Your average is:"<
int get_score()
{
改成
void get_score(int *average, int *sum)
return ?不要了
average = (chin+math+phys+chem+engl)/5;
sum = chin+math+phys+chem+engl;
改成
*average = (chin+math+phys+chem+engl)/5;
*sum = chin+math+phys+chem+engl;
score = get_scores();改成
get_scores(&average, &sum);