zoukankan      html  css  js  c++  java
  • 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;
    }
    

      

  • 相关阅读:
    JSP 隐含对象
    Cookie 和 Session
    Servlet(Server Applet) 详解
    AbstractQueuedSynchronizer 详解
    ThreadLocal 详解
    线程的生命周期
    phpfor函数和foreach函数
    php的while函数
    php的switch函数
    php的if函数
  • 原文地址:https://www.cnblogs.com/ranwuer/p/9717893.html
Copyright © 2011-2022 走看看