编写一个程序,要求用户输入最多10个高尔夫成绩,并将其存储在一个数组中。  程序允许用户提早结束输入,并在一行上显示所有成绩,然后报告平均成绩。  请使用3个数组处理函数来分别进行输入、显示和计算

#include <iostream>
#include <math.h>
using namespace std;

int const maxscore = 10;
int TrueSize = 0;

int main()
{
	cout << "Input the score of golf!" <<endl;
	void SaveGolf(int *golf);
	void ShowGolf(const int *golf);
	void AverageGolf(const int *golf);
	
	int golf[maxscore];
	SaveGolf(golf);
	ShowGolf(golf);
	AverageGolf(golf);

	return 0;
}

void SaveGolf(int *golf)
{
	cout << "If you want to end the input, press the letter!" << endl;
	for(int i =0; i < maxscore; i++)
	{
		cout << "Input the " << i+1 << " Score!" << endl;
		if(cin >> golf[i])
		{
		}
		else
		{
			TrueSize = i;
			break;
		}
		TrueSize = i;
	}
	cout << "Enter end!" << endl;
}

void ShowGolf(const int * golf)
{
	cout << "Show the golf socre!" << endl;

	for(int i = 0; i < TrueSize ; i++)
	{
		cout << golf[i] << '\t';
	}
	cout << endl;
}

void AverageGolf(const int *golf)
{
	int sum = 0;
	for(int i = 0; i < TrueSize; i++)
	{
		sum += golf[i];
	}
	cout << "The score average is : " << sum / TrueSize << "!" << endl;
}

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值