Im having some problems identifying where my error is. I've read through the post on this topic and applied the responses to my code but it's still giving me a warning. I am trying to use an array to compute the average of 10 numbers.

#include <iostream>
using namespace std;

double arrayAverage (double sumAverage[10]) ;


int main(){
	double sumAverage[10];
	int k ;
	double sum ;
	double average = 0 ;
	k = 0;
	sum = 0;
	cout << "Input 10 positive numbers" << endl;
	cin >> sumAverage[k];

	arrayAverage(sumAverage);
	return 0;
}

double arrayAverage(double sumAverage[10]){

	for(int k = 0; k < 10; k ++){
		
		double sum = sum + sumAverage[k];
		double average = sum/10;

		cout << "The average of your 10 numbers is" << average << endl;
		return k;
		}
}
double sumAverage[10];
int k ;
double sum ;
double average = 0 ;
k = 0;
sum = 0;
cout << "Input 10 positive numbers" << endl;
cin >> sumAverage[k];

Will only let you enter one number for sumAverage[0], the rest of the elements need to be initialised with a value either in a loop or otherwise.

Im having some problems identifying where my error is. I've read through the post on this topic and applied the responses to my code but it's still giving me a warning. I am trying to use an array to compute the average of 10 numbers.

double sum = sum + sumAverage[k];
		double average = sum/10;

What's the 1st value of sum when you do this? What value are you adding sumaverage[k] to?

This article has been dead for over six months. Start a new discussion instead.