Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Function call for arrays.

$
0
0
Error:
1. '=' : cannot convert from 'double []' to 'int'
2. '+=' : illegal, right operand has type 'double []'
3. '+=' : cannot convert from 'double []' to 'double'

And I'm not sure whether the function call is right or wrong. I've tried to correct it, but failed.

#include <iostream>
#include <string>
using namespace std;
void getData(double rain[]);

int main()
{
	getData(rain);
}

void getData(double rain[])
{
	const int N_MONTHS = 12;
	int rain;
	int values[N_MONTHS];
	int count;
	double total = 0;
	double avg;
	int largest;
	int smallest;
	string p_months[N_MONTHS] = { "January", "February", "March", "April", 
								  "May", "June", "July", "August", "September", 
								  "October", "November", "December" };
								  
	for ( int month = 1; month <= N_MONTHS; month++ ){
		cout << "Enter the total rainfall for " << p_months[month-1] << ": ";
		cin >> rain;
		
		if ( rain < 0 ){
			 cout << "The number you have entered is invalid." << endl;
			 cout << "Please reenter: ";
			 cin >> rain;
		}

		values[month-1]=rain; 			 
		total += rain;
	}
	
	cout << "The total amount of rain is: " << total << endl;
	avg = total / (double)N_MONTHS;
	cout << "The average amount of rainfall is " << avg << endl;
	
	 for ( int month = 1; month <= N_MONTHS; month++ ){
		 largest = values[0];
		 for ( count = 1; count < N_MONTHS; count++ ){
			 if ( values[count] > largest ){
				  largest = values[count];
			 } 
		 }
		 
		 smallest = values[0];
		 for ( count = 1; count < N_MONTHS; count++ ){
			 if ( values[count] < smallest ){
				  smallest = values[count];
			 }
		 }
	 }
	
	cout << "The largest value is " << largest << endl;
	cout << "The smallest value is " << smallest << endl;
}




THANKS IN ADVANCE.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>