Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started