My error: Myprograms.exe has stopped working
a problem caused the program to stop working correclty. windows will close the program and notify you if a solution is available
#include <iostream>
#include <string>
//Constant to hold number of months
const int NUM_MONTHS = 12;
//call function getInput
getInput(rainArray);
//call function getTotal
totalRainfall = getTotal(rainArray);
//call function getAverage
averageRainfall = getAverage(totalRainfall, rainArray);
//call function getHighest
highest = getHighest(rainArray);
//call function getLowest
lowest = getLowest(rainArray);
//call function displayOutput
displayOutput(rainArray, highest, lowest);
return 0;
}
//function getInput - precondition - prompt the user to input 12 values and store them in a array(rainArray as parameter)
//Make sure user cannot enter negative number(use while loop)
//postcondition - the array has been populated
void getInput(double rainArray[])
{
using namespace std;
int counter=0, input;
cout << "Enter the amount of rainfall for each month of the year\n";
while (counter < NUM_MONTHS)
{
cin >> input;
if (input > 0)
{
rainArray[counter] = input;
counter++;
}
else
{
cout << "Rainfall must be greater than 0.\n";
cout << "Please enter correct total.\n";
}
}
}
//function getTotal - precondition - access to array of 12 values(rainArray as parameter)
//Accumulate the monthly values(using a for loop)
//postcondition - returns the total rainfall for the year
double getTotal(double rainArray[])
{
using namespace std;
double total = 0;
for (int count = 0; count < NUM_MONTHS; count++)
total += rainArray[count];
return total;
}
//function getAverage - precondition - access to total rainfall(totalRainfall as parameter)
//Divide from the total from the number of months
//postcondition - returns the total average for the year
double getAverage(double totalRainfall, double rainArray[])
{
using namespace std;
double average = 0;
average = getTotal(rainArray) / NUM_MONTHS;
return average;
}
//function getHighest - precondition - access to array of 12 values(rainArray as paramter)
//Store highest value from rainArray in to variable highestRainfall and return(using for loop)
//post condition - returns the highest amount of rainfall for the year
double getHighest(double rainArray[])
{
double highest;
highest = rainArray[0];
for (int month = 1; month < NUM_MONTHS; month++)
{
if (rainArray[month] > highest)
{
highest = rainArray[month];
}
}
return highest;
}
//function getLowest - precondition - access to array of 12 values(rainArray as parameter)
//Store lowest value from rainArray in to variable lowestRainfall and return(using for loop)
//postcondition - returns the lowest amount of rainfall for the year
double getLowest(double rainArray[])
{
double lowest;
lowest = rainArray[0];
for (int month = 1; month < NUM_MONTHS; month++)
{
if (rainArray[month] < lowest)
{
lowest = rainArray[month];
}
}
return lowest;
}
//function displayOutput - preconditon - needs to know the array and the averageRainfall
//Use for loop to display the amount of months and subtract each array element by the averageRainfall
//postcondition - outputs the month number and the difference between rain amount and the average
void displayOutput(double rainArray[], double highest, double lowest)
{
using namespace std;