0

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;
		}
}
3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by WaltP
0
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.

0

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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.