c++ 输入10个数,显示它的平均分

#include <iostream>
using namespace std;

void inputScores(double golfScores[], int size);
void displayScores(double golfScores[], int size);
void averageScores(double golfScores[], int size);


int main() {
	cout << "Pealse input 10 golf scores: " << endl;
	const int INPUT_COUNT = 10;
	double golfScores[10];
	inputScores(golfScores, INPUT_COUNT);
	displayScores(golfScores, INPUT_COUNT);
	averageScores(golfScores, INPUT_COUNT);
	return 0;
}

void inputScores(double golfScores[], int size) {
	for (int i = 0; i < size; i++) {
		cout << '#' << i+1 << ':';
		cin >> golfScores[i];
	}
}

void displayScores(double golfScores[], int size) {
	cout << "Your scores: ";
	for (int i = 0; i < size; i++) {
		cout << golfScores[i] << ' ';
	}
	cout << endl;
}

void averageScores(double golfScores[], int size) {
	double sum = 0;
	double average;
	for (int i = 0; i < size; i++) {
		sum += golfScores[i];
	}
	average = sum / size;
	cout << "Average score: " << average << endl;
}

  

posted @ 2018-09-28 12:13  ranwuer  阅读(1099)  评论(0编辑  收藏  举报