so i need help printing my months array with my rain array in the code below for
ID: 3655560 • Letter: S
Question
so i need help printing my months array with my rain array in the code below for the highest and lowest months with rain... it works when i show every month with the for loop im using but im not printing the month with the lowest/highest amount of rain im only printing the amount... i have month[12] but it doesnt work... please advise how to print the highest and low int main() { double rain[12]; string months[] = {"January", "Febuary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; double sum; double high; double low; for(int i = 0; i < 12; i++) { cout << "Enter rain, in inches, for " << months[i] << ": " << endl; cin >> rain[i]; } for(int i = 0; i < 12; i++) { cout << "It rained " << rain[i]<< " " << "inches in " << months[i] << endl; } sum = total(rain); cout << "It rained " << sum << " inches for the whole year!!!" << endl; cout << "It rained " << sum/12 << " inches on average each month!!!" << endl; high = highest(rain); cout << high << " was the highest rain for " << months[12]; low = lowest(rain); cout << low << " was the lowest rain for " << months[12] << endl; char b; cout << endl << endl << "Enter anything"; cin >> b; return 0; }Explanation / Answer
1) Make sure that your prototypes match the parameters and types you have defined in the functions themselves. Remember the prototypes are to tell the compiler what is coming up so it can get ready for it. You don't want to throw a curve ball by changing the signature of a function. 2) Also you had getHighest defined and not getLargest. Make sure you match the names. 3) Notice that rainfall holds doubles, not ints. So you can't pass rainfall as an array of integers. Also you need double brackets to show that it is an array. 4) You got yourself mixed up between an array called NUM_MONTH and your constant NUM_MONTHS. You never needed NUM_MONTH since all your values were in rainfall. 5) Make sure you check for semicolons. You forgot one after getTotal in your getAverage function. That line has been removed anyways in this updated code below. Just saying to keep an eye out for those. 6) You forgot closing curly braces on your functions getHighest (aka getLargest) and getSmallest. Make sure that all closing braces match all opening curly braces. 7) Make sure you define all variables and array names before you use them. In getaverage you didn't define total or average before attempting to use them. In getHighest and getSmallest you also didn't define "values". No matter, this is actually suppose to be rainfall again because that is where your values are. #include 004 #include 005 using namespace std; 006 007 // Constant for the number of months 008 const int NUM_MONTHS = 12; 009 010 // Function prototypes 011 // These must match your signatures exactly. Since you define a constant 012 // you only need to provide the array. Also you defined getLargest and getHighest 013 // so make sure you check your functions names to see if they match. 014 // Prototypes are also only needed if you don't define the function BEFORE main. 015 double getTotal(double []); 016 double getAverage(double []); 017 double getLargest(double [], int &); 018 double getSmallest(double [], int &); 019 020 021 int main() 022 { 023 // Array to hold the rainfall data 024 double rainFall[NUM_MONTHS]; 025 026 // Get the rainfall for each month. 027 for (int month = 0; monthRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.