Need help on a programming assignment

I need to:

"...write a program that reads up to 20 decimal values of weekly rainfall for a given city. The program should ask the user how many weeks of data they want to enter, then uses a function to input the values and stores them in an array. The program must use a function to calculate and return the average rainfall.

The output of the program displays all rainfall values entered followed by the amount above or below the average for each week. Finally, the program displays the smallest and largest rainfall values for the year..."

Please help me get started. Thanks!

-shywolf91
Last edited on
Here is what I got so far. Plase help. I use borland c++ and get 1 error:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//Problem set 10; Exercise 1;
//Written by: Dylan Metz

#include <iostream.h>

void GetRain(double[ ],int);
double CalAverageRain(double[], int);

int main()
{
const int SIZE=20;
double Array[SIZE];
double average, smallest, largest;

int weeks; //user input:# of weeks.

cout<<"How many weeks of data would you like to input? ";
cin>>weeks;

//call function to get array values
GetRain(Array,weeks);
//call function to calculate average
average=CalAverageRain(Array,weeks);

//display values followed by amount above of below average & determine largest
//and smallest


smallest=largest=Array[0];
for(int x=0;x<weeks-1;x++)
{
 if(Array[x]<smallest)
 {
  smallest=Array[x];
  }
  if(Array[x]>largest)
  {
	largest=Array[x];
  }
  if(Array[x]>average)
  {
	cout<<Array[x]<<" is above the average by "<<(Array[x]-average)<<endl;
  }
  else
  {
	cout<<Array[x]<<" is below the average by "<<(average-Array[x])<<endl;
  }
}

 //Display smallest and largest rainfall values
 cout<<"The largest is "<<largest<<endl;
 cout<<"The smallest is "<<smallest<<endl;


//functions

void getRain(double Array[], int weeks)
{
	for(int x=0;x<weeks-1;x++)
	{
		cout<<"Enter an rainfall amount:";
		cin>>Array[x];
	}

}

double calcAverageRain(double Array[], int weeks)
{
	double sum=0, average;
	for(int x=0;x<weeks-1;x++)
	{
		sum+=Array[x];
	}
	average = sum/weeks;
	return average;
}


 return 0;
}
Your functions go outside main. You have to completely finish the main function, and then you can write the other functions.
Thanks
Topic archived. No new replies allowed.