So, I have an array called rainfall which has data of rainfall for 12 months stored in. And also a string array for the months (jan,feb...). And I will have to sort the rainfall array from highest to lowest. How do I connect this 2 arrays, so I can print them out together properly after sorting out the rainfall array.
This is my code :
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
void selectionSort(double array[],int size)
{
int startScan, minIndex, maxValue;
for(startScan = 0; startScan < (size - 1); startScan++)
{
minIndex = startScan;
maxValue = array[startScan];
for(int index = startScan + 1; index < size; index++)
{
if (array[index] > maxValue)
{
maxValue = array[index];
minIndex = index;
}
}
array[minIndex] = array[startScan];
array[startScan] = maxValue;
}
}
void highestfunction(double highestrainfall[], string monthtemp[])
{
double highest;
highest = highestrainfall[0];
string highestmonth = "January";
for (int count = 1; count < 12; count++)
{
if (highestrainfall[count] > highest)
{
highest = highestrainfall[count];
highestmonth = monthtemp[count];
}
}
cout << highestmonth << " has highest amount of rainfall: " << highest << " ml" << endl;
}
void lowestfunction(double lowestrainfall[], string monthtemp[])
{
double lowest;
lowest = lowestrainfall[0];
string lowestmonth = "January";
for (int count = 1; count < 12; count++)
{
if(lowestrainfall[count] < lowest)
{
lowest = lowestrainfall[count];
lowestmonth = monthtemp[count];
}
}
cout << lowestmonth << " has lowest amount of rainfall: " << lowest << " ml" << endl;
}
int main()
{
string months[] = { "January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"};
double rainfall[12];
double total = 0;
double average;
int count;
for (count = 0; count < 12; count++)
{
cout << "Enter the total rainfall (in milliliter) of " << months[count] << ": ";
cin >> rainfall[count];
while(rainfall[count] < 0)
{
cout << "Invalid input!!! Please try again. " << endl;
cout << "Enter the total rainfall (in milliliter) of " << months[count] << ": ";
cin >> rainfall[count];
}
}
for (count = 0; count <12; count++)
{
total += rainfall[count];
}
cout << "----------------------------------------" << endl;
cout << setprecision(2) << showpoint << fixed;
cout << "The total rainfall for a year is: " << total << " ml" << endl;
average = (total / 12);
cout << "The average rainfall monthly rainfall is " << average << " ml" << endl;
highestfunction(rainfall, months);
lowestfunction(rainfall, months);
selectionSort(rainfall, 12);
cout << "List of the months, sorted in order of rainfall from highest to lowest" << endl;
for(count = 0; count < 12; count++)
{
cout << rainfall[count] <<" ml" << endl;
}
return 0;
}
As I understand, you want label each rainfall with a month.
Therefore you can define a struct. For example;
struct RainfallDefinition
{
string month;
double rainfall;
}
now you can use array of RainfallDefinition and sort with respect to rainfall attribute.
If you do not use structs, you can use pair. However, in my opinion using struct is more reliable and readable. You can extend your RainfallDefinition any time. For example, you can also add int year; , int day; attributes etc. and then you can sort without losing any info.
i could suggest a simple algo for it...
take two arrays one array of strings which contains the months...name it
`
string month[12];
/* i.e. 12 months initially give em the month names in regular order...i.e. starting from jan to dec...*/
second array would be a 2 dimensional array...
`
int rainfall[12][2];
// rainfall[i][j] likewise you know rows and columns respectively i m considering
`
put values in it initially like
`
rainfall[0][0]=150; // this is the amount of rainfall in litre or whatever unit
rainfall[0][1]=0;
/* here 2nd column contains the index of month in string, i.e. for now it is 0 that is January...likewise*/
now you sort the rainfall array for the values in rainfall[i][0] and where ever you swap two values for sorting... suppose you swap rainfall[1][0] to rainfall[3][0] then in the next statement in which you swap them...also swap their respective indices...
so in the end u would be having array rainfall in a sorted manner so when u want rainfall[i][0] 's month.. you can check it by month[rainfall[i][1]] ...
**This thing can also be done using pointers and linked list...even a little more efficiently but i did this because when i have choice between using linked list using pointers and without it... i prefer without it
**this could also be done using structure but here is the most organic way i found...
Related
I have an assignment where I need to get user input for the amount of rainfall for each month. At the end I need to average the rainfall as well as display the month (using the name of the month) that had the highest and the lowest rainfall. Everything works with the exception of displaying the lowest and highest month. For some reason my code always displays December instead of the actual lowest and highest month. The lowestMonth = MONTHS[count]; and highestMonth = MONTHS[countup]; are the lines of code that I suspect are causing some problems. Appreciate any help the community can offer.
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <string>
using namespace std;
int main()
{
const int SIZE = 12;
double RAINFALL[SIZE];
string MONTHS[SIZE] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
for (int counter = 0; counter < SIZE; counter++)
{
cout << "Please enter rainfall for " << MONTHS[counter] << ": ";
cin >> RAINFALL[counter];
while (RAINFALL[counter] < 0.00) // Input validation to prevent neg amounts being entered
{
cout << "Invalid Data (negative rainfall)!" << endl;
cout << "Please re-enter rainfall for " << MONTHS[counter] << ": ";
cin >> RAINFALL[counter];
}
}
int tnum;
double average, sum = 0;
for (tnum = 0; tnum < SIZE; tnum++)
sum += RAINFALL[tnum];
average = sum / SIZE;
cout << "Average rainfall = " << average << endl;
int count;
int lowest;
string lowestMonth = MONTHS[0];
lowest = RAINFALL[0];
for (count = 1; count < SIZE; count++)
{
if (RAINFALL[count] < lowest)
lowest = RAINFALL[count];
lowestMonth = MONTHS[count];
}
cout << "Lowest rainfall in " << lowestMonth << " of: " << lowest << endl;
int countup;
int highest;
string highestMonth = MONTHS[0];
highest = RAINFALL[0];
for (countup = 1; countup < SIZE; countup++)
{
if (RAINFALL[countup] > highest)
highest = RAINFALL[countup];
highestMonth = MONTHS[countup];
}
cout << "Highest rainfall in " << highestMonth << " of: " << highest << endl;
return 0;
}
You are missing a bracket in your if-statement, so only the first line is executed.
for (count = 1; count < SIZE; count++)
{
if (RAINFALL[count] < lowest) { // <-- BRACKET
lowest = RAINFALL[count];
lowestMonth = MONTHS[count];
} // <-- BRACKET
}
There are more modular ways of doing this, of course:
std::string lowest_month = MONTHS[
std::min_element(&RAINFALL[0], &RAINFALL[SIZE]) - &RAINFALL[0]
];
I'm writing code that asks about rainfall each month, then outputs yearly total, monthly average, min, and max rain month (index). My code is almost complete, except that instead of outputting the max value the output always shows the max range of the variable type 32767 (e.g. if rain is 70mm and maximum, console shows 32767 always). Thanks for your help. I'm self-learning.
I have tried the following code.
#include<iostream>
using namespace std;
int main(){
const int numMonths = 3;
double monthlyRain[numMonths]={0,0,0};
string monthName[numMonths]= {"Jan", "Feb", "Mar"};
int count = 0;
int indexWettest = 0;
int indexDriest = 0;
double yearTotal=0, monthlyAverage=0;
double monthHighest;
double monthLowest;
monthLowest = monthlyRain[0];
monthHighest = monthlyRain[0];
// enter monthly rain;
for (int count=0; count < numMonths; count++){
cout << "Please enter amount of rain in " << monthName[count] << endl;
cin >> monthlyRain[count];
}
// print month and corresponding rain amount;
cout << "Month --- Rain(mm)" << endl;
for (int count = 0; count < numMonths; count++){
cout << monthName[count] << " " << monthlyRain[count] << endl;
}
// calculate year total;
for (int count = 0; count < numMonths; count++){
yearTotal += monthlyRain[count];
}
// calculate average monthly rainfall;
monthlyAverage = yearTotal/numMonths;
// find month with lowest rainfall;
// find month with highest rainfall;
for (int count = 0; count < numMonths; count++){
if (monthlyRain[count] > monthHighest){
monthHighest = monthlyRain[count+1];
indexWettest = count;
}
}
// PROBLEM IS HERE!;
for (int count = 0; count < numMonths; count++){
if (monthlyRain[count] < monthLowest){
monthLowest = monthlyRain[count];
indexDriest = count;
}
}
cout << "Total yearly rain fall is: " << yearTotal << endl;
cout << "Average monthly rainfall is: " << monthlyAverage << endl;
cout << "The driest month is " << monthName[indexDriest] << " with rain amount of " << monthLowest << endl;
cout << "The wettest month is " << monthName[indexWettest] << " with rain amount of " << monthHighest << endl; //<< monthName[indexWettest];
return 0;
}
Expected result is the user input.
Read compiler warnings.
main.cpp:35:19: warning: 'yearTotal' may be used uninitialized in this function [-
Wmaybe-uninitialized]
yearTotal += monthlyRain[count];
Line that declares yearTotal should be double yearTotal = 0;
Same with other variables. Always initialize them.
currently stuck on a homework problem and hoping for some hints as to why my code isn't working / what I'm missing. The homework question asks you to make an array that holds a string of salsa flavors for a store, gathers data from the user input on how many were sold (jars) and then display the total sales from each flavor sold. Ive got all that down, but the question goes on to ask you to retrieve the best seller and the worst seller. I've attempted and can get my code to pull two flavors, but they're completely incorrect. Any help is appreciated! Here is my code:
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
// variables
const int SIZE = 5;
string salsas[SIZE] = { "Mild", "Medium", "Sweet", "Hot", "Zesty"};
//names of salsas
int jars[SIZE]; //holds number of jars user enters
int sales[SIZE]; //holds sales numbers
int count; //counts for a loop
int largest; //largest sale
int smallest; //smallest sale
cout << "Enter the monthly number of jars sold for each type of
salsa.\n\n";
// Display the salsas in the array
for (int count = 0; count < SIZE; count++)
{
cout << salsas[count] << ": ";
cin >> jars[count];
}
// Display salsa sales
cout << "\nEach jar of salsa, no matter the type, costs $5.50.\n";
cout << "Here are the monthly sales numbers for each type of salsa.
\n\n";
cout << fixed << showpoint << setprecision(2);
for (int count = 0; count < SIZE; count++)
{
double sales = jars[count] * 5.50;
cout << salsas[count] << ": $";
cout << sales << endl;
}
//Gets highest sale
{
int count;
int largest = sales[0];
int index = 0;
for (count = 0; count < SIZE; count++)
{
if (sales[count] > largest)
{
largest = sales[count];
index = count;
}
}
cout << "\nBest Seller: " << salsas[index] << endl;
}
//Gets lowest sale
{
int count;
int smallest = sales[0];
int index = 0;
for (count = 0; count < SIZE; count++)
{
if (sales[count] < smallest)
{
smallest = sales[count];
index = count;
}
}
cout << "\nWorst Seller: " << salsas[index] << endl;
}
return 0;
}
One of the biggest hindrances in debugging your own code is in naming your variables. If you've declared count, largest, and smallest variables at the start of your main() function but you redeclare them in a separate block later on. It's downright redundant.
The actual bug is that you're not actually calculating and filling your sales[] array. Comparing them later on for largest and smallest wouldn't work as intended.
Look for this line in the code below
sales[count] = jars[count] * 5.50;
Lé Code
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
// variables
const int SIZE = 5;
string salsas[SIZE] = { "Mild", "Medium", "Sweet", "Hot", "Zesty"};
//names of salsas
int jars[SIZE]; //holds number of jars user enters
int sales[SIZE]; //holds sales numbers
// int count; //counts for a loop // no need
// int largest; //largest sale // no need
// int smallest; //smallest sale // no need
cout << "Enter the monthly number of jars sold for each type of salsa.\n\n";
// Display the salsas in the array
for (int count = 0; count < SIZE; count++)
{
cout << salsas[count] << ": ";
cin >> jars[count];
}
// Display salsa sales
cout << "\nEach jar of salsa, no matter the type, costs $5.50.\n";
cout << "Here are the monthly sales numbers for each type of salsa. \n\n";
cout << fixed << showpoint << setprecision(2);
for (int count = 0; count < SIZE; count++) // declare `count` where it is used
{
sales[count] = jars[count] * 5.50; // calculate sales[count] IMPORTANT
cout << salsas[count] << ": $";
cout << sales[count] << endl; // show appropriate output
}
//Gets highest sale
int largest = sales[0]; // declare largest and index closest to where they are used
int index = 0;
for (int count = 0; count < SIZE; count++)
{
if (sales[count] > largest)
{
largest = sales[count];
index = count;
}
}
cout << "\nBest Seller: " << salsas[index] << endl;
//Gets lowest sale
int smallest = sales[0]; // declare smallest closest to where it is used
index = 0; // reuse your old variable
for (int count = 0; count < SIZE; count++)
{
if (sales[count] < smallest)
{
smallest = sales[count];
index = count;
}
}
cout << "\nWorst Seller: " << salsas[index] << endl;
return 0;
}
Sample Console Interaction
Enter the monthly number of jars sold for each type of salsa.
Mild: 20
Medium: 10
Sweet: 5
Hot: 2
Zesty: 1
Each jar of salsa, no matter the type, costs $5.50.
Here are the monthly sales numbers for each type of salsa.
Mild: $110
Medium: $55
Sweet: $27
Hot: $11
Zesty: $5
Best Seller: Mild
Worst Seller: Zesty
I'm completely new to Stack OverFlow so excuse me if I'm breaking any rules or incorrectly asking a question (I would also appreciate advice on how to properly ask questions on Stack overflow).
Anyways so I get this error
*"argument of type 'data *' is incompatible with parameter of type 'data '."
when I call the user-defined function weather in int main(). I would appreciate it if someone could take a look at my code and guide me to what's causing the error. Just so you know, I am currently taking a programming fundamentals intro course and I have not learned about classes and pointers yet.
Thanks!
#include <iostream>
#include <string>
using namespace std;
const int SIZE = 2;
void weather(struct data array[], int SIZE, string months[]);
int main()
{
string months[12] = { "January", "February", "March", "April", "May", "June"
"July", "August", "September", "October", "November", "December" };
struct data {
double totalRainfall;
double highTemp;
double lowTemp;
double avgTemp;
};
data annualWeather[SIZE];
//Asks user for total rainfall, high and low temperature, and calculates
//avg temperature of each month
for (int i = 0; i < SIZE; i++)
{
cout << "What was the total rainfall in " << months[i]
<< "?" << endl;
cin >> annualWeather[i].totalRainfall;
//Prompts user for temperature high
do
{
cout << "What was the temperature high in " << months[i]
<< "?" << endl;
cin >> annualWeather[i].highTemp;
} while (annualWeather[i].highTemp > 140);
//Prompts user for temperature low
do
{
cout << "What was the temperature low in " << months[i]
<< "?" << endl;
cin >> annualWeather[i].lowTemp;
} while (annualWeather[i].lowTemp < -100);
annualWeather[i].avgTemp = (annualWeather[i].highTemp + annualWeather[i].lowTemp) / 2;
}
**weather(annualWeather, SIZE, months); <--THIS IS WHERE I SEE ERROR**
return 0;
}
void weather(struct data array[], int SIZE, string months[])
{
double avgRainFall = 0;
double totalAnnualRainFall = 0;
double annualHigh = 0;
double annualLow = 0;
double avgMonthlyTemp = 0;
//Calculates sum annual rain fall, total annual rain fall, and total average monthly temperature
for (int i = 0; i < SIZE; i++)
{
avgRainFall += annualWeather[i].totalRainfall;
totalAnnualRainFall += annualWeather[i].totalRainfall;
avgMonthlyTemp += annualWeather[i].avgTemp;
}
//Calculates average annual rain fall and average annual monthly temperature
avgRainFall = avgRainFall / SIZE;
avgMonthlyTemp = avgMonthlyTemp / SIZE;
//Selection Sort of annualWeather[].highTemp
for (int index = 0; index < SIZE - 1; index++)
{
//Find location of smallest element
int smallestIndex = index;
for (int location = index + 1; location < SIZE; location++)
if (annualWeather[location].highTemp < annualWeather[smallestIndex].highTemp)
smallestIndex = location;
//Swap smallest element of annualWeather[].highTemp to front
int tempSales = annualWeather[smallestIndex].highTemp;
annualWeather[smallestIndex].highTemp = annualWeather[index].highTemp;
annualWeather[index].highTemp = tempSales;
//Swap smallest element of months[] to front
string tempMonths = months[smallestIndex];
months[smallestIndex] = months[index];
months[index] = tempMonths;
}
//Displays average monthly rainfall, total annual rainfall, annual high, annual low,
//And average of the monthly temperature averages
cout << "The average monthly rainfall is " << avgRainFall << "." << endl
<< "The total rainfall for the year is " << totalAnnualRainFall << "."
<< endl << "The high temperature of the year is " << annualHigh << " during "
<< months[0] << endl << "The low temperature of the year is " << annualLow << " during "
<< months[2] << endl << "The average temperature of all the monthly averages is "
<< avgMonthlyTemp << ".";
cin.get(); cin.get();
}
The struct data declared in your main function is different from the struct data used in the prototype of your weather function.
Move the definition of struct data out of main to the global namespace, somewhere before you use it to declare weather.
For the first please specified your personal data types in global space.
Your problem not in sending array to function. Problem inside your function
you send array to them with name array, and inside trying to access them by name from main. Just rename your function parameter.
void weather(Data array[], int SIZE, string months[])
{
double avgRainFall = 0;
double totalAnnualRainFall = 0;
double annualHigh = 0;
double annualLow = 0;
double avgMonthlyTemp = 0;
//Calculates sum annual rain fall, total annual rain fall, and total average monthly temperature
for (int i = 0; i < SIZE; i++)
{
avgRainFall += array[i].totalRainfall;
totalAnnualRainFall += array[i].totalRainfall;
avgMonthlyTemp += array[i].avgTemp;
}
//Calculates average annual rain fall and average annual monthly temperature
avgRainFall = avgRainFall / SIZE;
avgMonthlyTemp = avgMonthlyTemp / SIZE;
//Selection Sort of annualWeather[].highTemp
for (int index = 0; index < SIZE - 1; index++)
{
//Find location of smallest element
int smallestIndex = index;
for (int location = index + 1; location < SIZE; location++)
if (array[location].highTemp < array[smallestIndex].highTemp)
smallestIndex = location;
//Swap smallest element of annualWeather[].highTemp to front
int tempSales = array[smallestIndex].highTemp;
array[smallestIndex].highTemp = array[index].highTemp;
array[index].highTemp = tempSales;
//Swap smallest element of months[] to front
string tempMonths = months[smallestIndex];
months[smallestIndex] = months[index];
months[index] = tempMonths;
}
//Displays average monthly rainfall, total annual rainfall, annual high, annual low,
//And average of the monthly temperature averages
cout << "The average monthly rainfall is " << avgRainFall << "." << endl
<< "The total rainfall for the year is " << totalAnnualRainFall << "."
<< endl << "The high temperature of the year is " << annualHigh << " during "
<< months[0] << endl << "The low temperature of the year is " << annualLow << " during "
<< months[2] << endl << "The average temperature of all the monthly averages is "
<< avgMonthlyTemp << ".";
cin.get(); cin.get();
}
Can anyone help me figure out how to get the 3rd parameter of the getLowest/getHighest function to reference the names array that has the months of the year and display the names of the month when I call for it? What's supposed to happen with those functions is that they are supposed to be able to give the name of the month that corresponds with the lowest/highest amount in the array. I can't seem to get it down. That's the last thing I need for this code and I'm trying very hard to figure it out. Any help would be much appreciated. Thank you.
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
//Function prototypes
double getTotal(double [], int);
double getAverage(double [], int);
double getLowest(double [], int, int&);
double getHighest(double [], int, int&);
int main()
{
const int months = 12;
string names[months] = { "January", "February", "March", "April",
"May", "June", "July", "August",
"September", "October", "November", "December" };
double rainfall[months];
double total, average, maxRain, minRain;
int indexofLowest, indexofHighest;
//Input from using for the rainfall amounts
std::cout << "Please enter the amount of rainfall in inches, that fell in each month.\n";
std::cout << "Enter the amount of rainfall for " << names[0];
std::cin >> rainfall[0];
std::cout << "Enter the amount of rainfall for " << names[1];
std::cin >> rainfall[1];
std::cout << "Enter the amount of rainfall for " << names[2];
std::cin >> rainfall[2];
std::cout << "Enter the amount of rainfall for " << names[3];
std::cin >> rainfall[3];
std::cout << "Enter the amount of rainfall for " << names[4];
std::cin >> rainfall[4];
std::cout << "Enter the amount of rainfall for " << names[5];
std::cin >> rainfall[5];
std::cout << "Enter the amount of rainfall for " << names[6];
std::cin >> rainfall[6];
std::cout << "Enter the amount of rainfall for " << names[7];
std::cin >> rainfall[7];
std::cout << "Enter the amount of rainfall for " << names[8];
std::cin >> rainfall[8];
std::cout << "Enter the amount of rainfall for " << names[9];
std::cin >> rainfall[9];
std::cout << "Enter the amount of rainfall for " << names[10];
std::cin >> rainfall[10];
std::cout << "Enter the amount of rainfall for " << names[11];
std::cin >> rainfall[11];
//Get total
total = getTotal(rainfall, months);
//Get average
average = getAverage(rainfall, months);
//Get the max amount of rain
maxRain = getHighest(rainfall, months, indexofHighest);
//Get the min amount of rain
minRain = getLowest(rainfall, months, indexofLowest);
//Display the total, average, highest/lowest
std::cout << "The total amount of rain for the year is " << total << " inches.\n";
std::cout << "The average amount of rain monthly is " << average << " inches per month.\n";
std::cout << "The month that had the highest amount of rainfall is " << names[indexofHighest] << " with " << maxRain << " inches.\n";
std::cout << "The month that has the lowest amount of rainfall is " << names[indexofLowest] << " with " << minRain << " inches.\n";
return 0;
}
//Definition of function getTotal
double getTotal(double rainfall[], int months)
{
double total = 0;
for (int count = 0; count < months; count++)
{
total += rainfall[count];
}
return total;
}
//Definition of function getAverage
double getAverage(double rainfall[], int months)
{
double total = 0;
double average = 0.0;
for (int count = 0; count < months; count++)
{
total += rainfall[count];
average = total / months;
}
return average;
}
//Defintion of function getLowest
double getLowest(double rainfall[], int months, int indexofLowest)
{
int count;
double lowest;
lowest = rainfall[0];
for (count = 1; count < months; count++)
{
if (rainfall[count] < lowest)
lowest = rainfall[count];
}
return lowest;
}
//Definition of function getHighest
double getHighest(double rainfall[], int months, int indexofHighest)
{
int count;
double highest;
highest = rainfall[0];
for (count = 1; count < months; count++)
{
if (rainfall[0] > highest)
highest = rainfall[count];
}
return highest;
}
I tried your code. You have a few bugs. I guess you need to try harder in the future. Anyways here is a working solution with minimal changes to your existing code -
//Defintion of function getLowest
double getLowest(double rainfall[], int months, int & indexofLowest)
{
int count;
double lowest;
lowest = rainfall[0];
for (count = 1; count < months; count++)
{
if (rainfall[count] < lowest)
{
lowest = rainfall[count];
indexofLowest = count;
}
}
return lowest;
}
//Definition of function getHighest
double getHighest(double rainfall[], int months, int & indexofHighest)
{
int count;
double highest;
highest = rainfall[0];
for (count = 1; count < months; count++)
{
if (rainfall[count] > highest)
{
highest = rainfall[count];
indexofHighest = count;
}
}
return highest;
}
You have to set indexofLowest and indexofHighest in your functions (and match their prototype):
//Defintion of function getLowest
double getLowest(double rainfall[], int months, int& indexofLowest)
int count;
double lowest;
lowest = rainfall[0];
for (count = 1; count < months; count++)
{
if (rainfall[count] < lowest) {
lowest = rainfall[count];
indexofLowest = count;
}
}
return lowest;
}
//Definition of function getHighest
double getHighest(double rainfall[], int months, int& indexofHighest)
{
int count;
double highest;
highest = rainfall[0];
for (count = 1; count < months; count++)
{
if (rainfall[count] > highest) { //there was a bug here in your code: ... rainfall[0]
highest = rainfall[count];
indexofHeighest = count;
}
}
return highest;
}
you can also use a function to input data (and maybe add a little error checking):
//Input from using for the rainfall amounts
int readData(string monthNames[], double rain[], int n) {
int i;
std::cout << "Please enter the amount of rainfall in inches, that fell in each month.\n";
for ( i=0; i<n; i++) {
std::cout << "Enter the amount of rainfall for " << monthNames[i];
std::cin >> rain[i]; //check this value somehow!
}
return i;
}