I am in dire need of help. I need this array to list the months as the user enters rainfall totals. then I need it to calculate the highest , lowest , average and total rainfall months. I can get it to do it without the months but not with the months. It also cannot accept negative numbers. can anyone help me.

``````//This program lets the user enter the total rainfall for each of the 12 months
//into an array  of doubles . the program should calculate and display the total
//rainfall for the year , the average monthly rainfall , and
//the months with the highest and lowest amounts
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

// Function prototypes
void getTestScores(double[], int);
double getTotal(const double[], int);
double getLowest(const double[], int);
double gethighest(const double[], int);
int ValidateInput(string Message);
int main()
{

const int SIZE  = 12;      // Array size
double testScores[SIZE], // Array of test scores

string months[SIZE]={"JANUARY","FEBUARY","MARCH",
"APRIL","MAY","JUNE","JULY",
"AUGUST","SEPTEMBER","OCTOBER",
"NOVEMBER","DECEMBER",};//Array to hold months
total,            // Total of the scores
lowestScore,      // Lowest test score
highestscore,      // highest score
average;          // Average test score

// Set up numeric output formatting.
cout << fixed << showpoint << setprecision(1);

// Get the test scores from the user.
getTestScores(testScores, SIZE);

// Get the total of the test scores.
total = getTotal(testScores, SIZE);

// Get the lowest test score.
lowestScore = getLowest(testScores, SIZE);

//get the highest score
highestscore = gethighest(testScores, SIZE);

// Calculate the average.
//  the array starts at zero.
average = total / (SIZE );

// Display the average.
cout << "The month with the lowest average rainfall "
<< "dropped is " << lowestScore<<"\n"
<<"The highest months rainfall total is\t\n"
<< highestscore<<"\n"<<"The average rainfall is\t\n"
<<average<<"\n"<<"The Total rainfall\n"<< total<<"\n";

system("PAUSE");
return 0;
}

//************************************************************
// The getTestScores function accepts an array and its size  *
// as arguments. It prompts the user to enter test scores,   *
// which are stored in the array.                            *
//************************************************************

void getTestScores(double scores[], int size)
{
// Loop counter
int index;

// Get each test score.
for(index = 0; index <= size - 1; index++)
{
cout << "Enter Rainfall for month "
<< (index +1) << ": ";
cin >> scores[index];
}
}

//****************************************************
// The getTotal function accepts a double array      *
// and its size as arguments. The sum of the array's *
// elements is returned as a double.                 *
//****************************************************

double getTotal(const double array[], int size)
{
double total = 0; // Accumulator

// Add each element to total.
for (int count = 0; count < size; count++)
total += array[count];

// Return the total.
}

//****************************************************
// The getLowest function accepts a double array and *
// its size as arguments. The lowest value in the    *
// array is returned as a double.                    *
//****************************************************

double getLowest(const double array[], int size)
{
double lowest;  // To hold the lowest value

// Get the first array's first element.
lowest = array[0];

// Step through the rest of the array. When a
// value less than lowest is found, assign it
// to lowest.
for (int count = 1; count < size; count++)
{
if (array[count] < lowest)
lowest = array[count];
}

// Return the lowest value.
return lowest;
}

//****************************************************
// The gethighest function accepts a double array and *
// its size as arguments. The lowest value in the    *
// array is returned as a double.                    *
//****************************************************

double gethighest(const double array[], int size)
{
double highest;  // To hold the highest value

// Get the first array's first element.
highest = array[0];

// Step through the rest of the array. When a
// value less than lhighest is found, assign it
// to highest.
for (int count = 1; count < size; count++)
{
if (array[count] > highest)
highest = array[count];
}

// Return the highest value.
return highest;
}

int ValidateInput(string Message)
{
bool valid = false;
int scores =1;
cout << Message.c_str() <<endl;
while(!valid)
{
cout << "Input cannot be less than 1:";
cin >> scores;
if (scores >= 1)
valid = true;
}
return scores;
}
``````
2
Contributors
3
Replies
16
Views
4 Years
Discussion Span
Last Post by Ancient Dragon

If you are going to plagerize someone else's program then at least change the function names so that people will think you write it for your homework assignment.

there is a program like this please could you link it so I can see the example , I pulled these from examples from my book, as per my instructions. I am looking for a good example .I do intend to fully rewrite this as it is a work in progress. I just am not interested in doing like most of my class is doing and searching online for a program coping pasting . I need help on a few sections of this program that I pulled from the book as , I was told to do. once I figure out how to code it I will do so. just needed to know how to get the string array to work with the double testscores [SIZE ]array and getting the if statement to work correctly is all.
``````int highest = GetHightest(...); // where ... are the parameters