Thank you all for the help on my previous post! I'm still having problems with converting to string from an integer when pulling the information from a function. I am trying to have the actual name of the month display to the output instead of the number that's associated with it. I'm not sure how to convert to the string successfully. It's working below with the number in it's place, but I just can't get it to display the string to the screen.
for example, I'm required to have the sentence: "The largest amount of rainfall was 12 inches for the month of January"
edit:To sum it up, I cannot get the functions to bring over the string, instead of the integer value. The declared functions at the top of my code are what my professor have given us to use, so I cannot do anything different with how they're declared.
// Declare const variables
const int TOTALMONTHS = 12;
// Declare array for months and rainfall
string months[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
double rainFall[TOTALMONTHS];
// Declare functions
double getLowest(double[], int, int&);
double getHighest(double[], int, int&);
int main()
{
int subscript;
for (int months = 0; months < TOTALMONTHS; months++)
{
// Get this month's rainfall.
cout << "Enter the rainfall (in inches) for ";
cout << monthNames[months] << ": ";
cin >> rainFall[months];
}
// Display the largest amount of rainfall.
cout << "The largest amount of rainfall was ";
cout << getHighest(rainFall, TOTALMONTHS, subscript)
<< " inches in month ";
cout << (subscript + 1) << "." << endl;
// Display the smallest amount of rainfall.
cout << "The smallest amount of rainfall was ";
cout << getLowest(rainFall, TOTALMONTHS, subscript)
<< " inches in month ";
cout << (subscript + 1) << "." << endl << endl;
// End of program
system("pause");
return 0;
}
double getLowest(double rainFall[], int TOTALMONTHS, int &subscript)
{
double smallest;
smallest = rainFall[0];
for (int months = 0; months < TOTALMONTHS; months++)
{
if (rainFall[months] < smallest)
{
smallest = rainFall[months];
subscript = months;
}
}
return smallest;
}
double getHighest(double rainFall[], int TOTALMONTHS, int &subscript)
{
double largest;
largest = rainFall[0];
for (int months = 0; months < TOTALMONTHS; months++)
{
if (rainFall[months] > largest)
{
largest = rainFall[months];
subscript = months;
}
}
return largest;
}