# C++ Cannot convert double to double?



## sirusx69 (Oct 13, 2007)

The assignment is to make a rainfall statistics program that allows the user to input total rainfall for each month and then output the total, monthly average and the month with the highest and lowest without using global variables.

I have the code done but I'm getting a compile error stating that my "Statistics" function cannot convert double to double. Any Suggestions?


```
// Rainfall Statistics.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;
void spacemaker();
void statistics(double , string );

int main()
{
double rainfall[11];
string months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec" };



	for(int i=0; i<=11; i++)
	{
invalid:
		cout << "Enter the amount of rainfall for " << months[i] << ": ";
		cin >> rainfall[i];
		if(rainfall[i] < 0)
		{
			spacemaker();
			cout << "Please enter a number greater than or equal to 0\n";
			spacemaker();
			goto invalid;
		}
	}
	statistics(rainfall, months);
	return 0;
}

void statistics(double rainfall[], string months[])
{
	string  monthhigh, monthlow;
	double high, low, total, monthavg;

	high = rainfall[0];
	low = rainfall[0];
	total = 0;
	monthavg = 0;

	for(int i=0; i<=12; i++)
	{
		total = total + rainfall[i];
	}

	monthavg = total / 12;

	for(int i=0; i<=12; i++)
	{
		if(rainfall[i] > high)
		{
			high = rainfall[i];
			monthhigh = months[i];
		}
		else if(rainfall[i] < low)
		{
			low = rainfall[i];
			monthlow = months[i];
		}
	}

	spacemaker();
	cout << "The Yearly total is: " << total << "\n";
	cout << "The monthly average is: " << monthavg << "\n";
	cout << "The month with the highest rainfall was " << monthhigh << " at " << high << endl;
	cout << "The month with the lowest rainfall was " << monthlow << " at " << low << endl;
	system("pause");
}

void spacemaker()
{
	cout << "\n" << "\n";
}
```


----------



## sirusx69 (Oct 13, 2007)

Lol fixed that issue..was dumb but now I get another. The program runs successfully up untill the end where I get a windows Debug error

"Debug Error!

Run-Time Check Failure #2 - Stack around the variable 'rainfall' was corrupted"


----------



## Swen (Apr 9, 2010)

try renaming the variable, could help sometimes


----------

