Answered step by step
Verified Expert Solution
Link Copied!

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[12]={0.00}; // Create an array to store rainfall data for each month
string months[]={"1","2","3","4","5","6","7","8","9","10","11","12"};
double getTotal =0.00;
double getLargest =0.00;
double getSmallest =0.00;
string largestMonth, smallestMonth;
// Loop through each month to collect rainfall data
for (int i =0; i 12; i++){
bool validInput = false;
while (!validInput){
cout "Enter the rainfall (in inches) for month #" months[i]": ";
cin >> rainfall[i];
// Input verification: Ensure input is not negative
if (rainfall[i]0){
cout "Rainfall must be 0 or more." endl;
cout "Please re-enter: ";
} else {
validInput = true; // If the input is valid, exit the input loop
getTotal += rainfall[i]; // Add total monthly rainfail
// Check for largest amount of rainfall
if (rainfall[i]> getLargest || i ==0){
getLargest = rainfall[i];
largestMonth = months[i];
}
// Check for smallest amount of rainfall
if (rainfall[i] getSmallest || i ==0){
getSmallest = rainfall[i];
smallestMonth = months[i];
}
}
}
}
cout endl;
double getAverage = getTotal /12.0; // Monthly average
// Display the requested statistics
cout "The total rainfall for the year is " fixed setprecision(2) getTotal " inches." endl;
cout "The average rainfall for the year is " fixed setprecision(2) getAverage " inches." endl;
cout "The largest amount of rainfall was " fixed setprecision(2) getLargest " inches in month " largestMonth "." endl;
cout "The smallest amount of rainfall was " fixed setprecision(2) getSmallest " inches in month " smallestMonth "." endl;
cout endl;
cout "Here are the rainfall amounts, sorted in ascending order:" endl;
cout "----------------------------------------" endl;
for (int i =0; i 12; i++){
for (int j = i +1; j 12; j++){
if (rainfall[j] rainfall[i]){
swap(rainfall[j], rainfall[i]);
swap(months[j], months[i]);
}
}
cout rainfall[i] endl;
}
return 0;
}
Im getting the following compilation failed, please help.
Compilation failed
main.cpp: In function 'bool testPassed(std::ofstream&)':
main.cpp:18:27: error: 'getTotal' was not declared in this scope
18 double studentResult = getTotal(sampleArray,12);
Compilation failed
main.cpp: In function 'bool testPassed(std::ofstream&)':
main.cpp:18:27: error: 'getAverage' was not declared in this scope
18| double studentResult = getAverage sampleArray, 12
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data, Mining, And Analytics Components Of Strategic Decision Making

Authors: Stephan Kudyba

1st Edition

1466568704, 9781466568709

More Books

Students also viewed these Databases questions