All pastes #824186 Raw Edit

Untitled

public text v1 · immutable
·published 2007-12-19 20:59 UTC
rendered paste body
#include <iostream>
using namespace std;

float getAvg (float number[], int n){
	float sum;
	float answer;
	
	for (int i=0; i < n; i++){
		sum += number[i];
	}
	answer = (sum)/n;
	return(answer);
}

int main() {
	
	int n;
	
	cout << "How many numbers do you want to type in? ";
	cin >> n;	
	float * p;

	p = new float[n];

	for (int i=0; i < n; i++){
		cout << "Enter number " << i+1 << ":";
		cin >> p[i];
	}
	cout << "Average is: "<< getAvg(p,n);
	
	delete[] p;
	return 0;
}