Get the Average of Numbers in C++

Download
Download is available until [expire_date]
  • Version
  • Download 20
  • File Size 1.26 KB
  • File Count 1
  • Create Date May 5, 2016
  • Last Updated May 5, 2016

Get the Average of Numbers in C++

Get the Average of Numbers in C++

This is a sample program in c++ that computes the average or mean of the numbers entered by the user.
Below is the formula on how to compute the average of the numbers entered by the user.
Average = sum of the numbers / the quantity of numbers entered by the user.

Example:
Average=50 / 10
Average = 5
Source code:

#include 

using namespace std;

int main()
{
    int numToCompute;
    double result=0, numbers, getAverage=0;


cout << "Enter a number : " << endl;
cin >> numToCompute;
cout << "Enter " << numToCompute << " numbers (1 per line)" << endl;

for (int x=1; x <= numToCompute; x++){
	cin >> numbers;
	result= result +  numbers;
	}

getAverage= result	/ numToCompute;

cout << "the average is: " << getAverage << endl;


    return 0;
}
, , , , , ,

Post navigation

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.