write a C programming that can run like this to find the rainfall data of 6 week
ID: 3872077 • Letter: W
Question
write a C programming that can run like this to find the rainfall data of 6 weeks with the data inported from a text file. do not use array. Notice that it's possible for the result to have two different days or week.
Daily Rainfal Total Week #1: 3 0 0 7 821 0 39mm Week #2 : 0 1 1 0 0 0 4 6mm Week #3: 9672000 24mm Week #4 : 0000013 4mm wee Week #6 : 1 0 1 0 0 0 0 2mm 0mm Total rainfall: 75mm (an average of 12.5mm per week) Driest week: 5 Wettest week: 1 Total rainfall on driest day of week: 7mm Con Monday, Saturday) Total rainfall on wettest day of week: 22mm Con Friday) liberty: ~/tmp/%Explanation / Answer
#include<iostream>
#include <iomanip>
using namespace std;
// Constant for the number of months
const int NUM_MONTHS = 12;
// Function prototypes
double getTotal(double [], int);
double getAverage(double [], int);
double getLargest(double [], int, int &);
double getSmallest(double [], int, int &);
double getTotal(int rainFall,double NUM_MONTHS[])
{
double total = 0;
for (int count = 0; count < NUM_MONTH; count++)
total += NUM_MONTH[count];
return total;
}
double getAverage(int rainFall,double NUM_MONTH[])
{getTotal(rainFall,NUM_MONTH)
average= total/NUM_MONTHS;
return average;
}
double getHighest(int rainFall, double NUM_MONTHS[]) //I left out the subScript peice as I was not sure how to procede with that;
{
double largest;
largest = NUM_MONTHS[0];
for ( int month = 1; month <= NUM_MONTHS; month++ ){
if ( values[month] > largest ){
largest = values[month];
return largest;
}
double getSmallest(int rainFall, double NUM_MONTHS[])
046
{
double smallest;
smallest = NUM_MONTHS[0];
for ( int month = 1; month <= NUM_MONTHS; month){
if ( values[month] < smallest ){
smallest = values[month];
return smallest;
}
int main()
{
// Array to hold the rainfall data
double rainFall[NUM_MONTHS];
// Get the rainfall for each month.
or (int month = 0; month < NUM_MONTHS; month++)
// Get this month's rainfall.
cout << "Enter the rainfall (in inches) for month #";
cout << (month + 1) << ": ";
cin >> rainFall[month];
// Validate the value entered.
while (rainFall[month] < 0)
{
cout << "Rainfall must be 0 or more. "
<< "Please re-enter: ";
cin >> rainFall[month];
}
}
// Set the numeric output formatting.
cout << fixed << showpoint << setprecision(2) << endl;
// Display the total rainfall.
cout << "The total rainfall for the year is ";
cout << getTotal(rainFall, NUM_MONTHS)
<< " inches." << endl;
// Display the average rainfall.
cout << "The average rainfall for the year is ";
cout << getAverage(rainFall, NUM_MONTHS)
<< " inches." << endl;
// Now display the largest & smallest amounts.
// The subscript variable will be passed by reference
// the the getLargest and getSmallets functions.
int subScript;
// Display the largest amount of rainfall.
cout << "The largest amount of rainfall was ";
cout << getLargest(rainFall, NUM_MONTHS, subScript)
<< " inches in month ";
cout << (subScript + 1) << "." << endl;
// Display the smallest amount of rainfall.
cout << "The smallest amount of rainfall was ";
cout << getSmallest(rainFall, NUM_MONTHS, subScript)
<< " inches in month ";
cout << (subScript + 1) << "." << endl << endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.