Question: c + + Here's my code: #include #include using namespace std; int main ( ) { double rainfall [ 1 2 ] = { 0
c
Here's my code:
#include
#include
using namespace std;
int main
double rainfall; Create an array to store rainfall data for each month
string months;
double getTotal ;
double getLargest ;
double getSmallest ;
string largestMonth, smallestMonth;
Loop through each month to collect rainfall data
for int i ; i ; i
bool validInput false;
while validInput
cout "Enter the rainfall in inches for month # monthsi: ;
cin rainfalli;
Input verification: Ensure input is not negative
if rainfalli
cout "Rainfall must be or more." endl;
cout "Please reenter: ;
else
validInput true; If the input is valid, exit the input loop
getTotal rainfalli; Add total monthly rainfail
Check for largest amount of rainfall
if rainfalli getLargest i
getLargest rainfalli;
largestMonth monthsi;
Check for smallest amount of rainfall
if rainfalli getSmallest i
getSmallest rainfalli;
smallestMonth monthsi;
cout endl;
double getAverage getTotal ; Monthly average
Display the requested statistics
cout "The total rainfall for the year is fixed setprecision getTotal inches." endl;
cout "The average rainfall for the year is fixed setprecision getAverage inches." endl;
cout "The largest amount of rainfall was fixed setprecision getLargest inches in month largestMonth endl;
cout "The smallest amount of rainfall was fixed setprecision getSmallest inches in month smallestMonth endl;
cout endl;
cout "Here are the rainfall amounts, sorted in ascending order:" endl;
cout endl;
for int i ; i ; i
for int j i ; j ; j
if rainfallj rainfalli
swaprainfallj rainfalli;
swapmonthsj monthsi;
cout rainfalli endl;
return ;
Im getting the following compilation failed, please help.
Compilation failed
main.cpp: In function 'bool testPassedstd::ofstream&:
main.cpp::: error: 'getTotal' was not declared in this scope
double studentResult getTotalsampleArray;
Compilation failed
main.cpp: In function 'bool testPassedstd::ofstream&:
main.cpp::: error: 'getAverage' was not declared in this scope
double studentResult getAverage sampleArray,
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
