Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need the program to determine which month has the hgihest rainfall and which month has the lowest rainfall. The code I have so far

I need the program to determine which month has the hgihest rainfall and which month has the lowest rainfall. The code I have so far is attached below. Please help with the code for determining the highest and lowest month for rainfall. Code MUST BE IN C++ please.

// Structured Data.cpp : This file contains the 'main' function. Program execution begins and ends there. //

#include #include

using namespace std; const int SIZE = 12;

struct weather { double totalrainfall; double hightemp; double lowtemp; double averagetemp;

};

void getinfo(weather x[]) { for (int i = 0; i < SIZE; i++) {

cout << " Please enter The total rainfall for month " << i << ": " << endl; cin >> x[i].totalrainfall; cout << " Please enter the highest temperature for month " << i << ": " << endl; cin >> x[i].hightemp; cout << " Please enter the lowest temperature for month " << i << ": " << endl; cin >> x[i].lowtemp; cout << " Please enter the Average temperature for month " << i << ": " << endl; cin >> x[i].averagetemp; }

} void Averagetemp(weather R[], int s) {

double sum = 0; for (int i = 0; i < s; i++) sum += R[i].averagetemp; cout << "The average temperature for the year is " << sum / s << endl; }

void Totalrain(weather R[], int s) {

double sum = 0; for (int i = 0; i < s; i++) sum += R[i].totalrainfall; cout << "The total rain for the year is " << sum << endl; }

void Averagerain(weather R[], int s) {

double sum = 0; for (int i = 0; i < s; i++) sum += R[i].totalrainfall; cout << "The average rainfall for the year is " << sum / s << endl; }

void HighestRainfall(double R[], string M[], int s) {

double max = R[0]; int indexH = 0; for (int i = 0; i < s; i++) {

if (R[i] > max) {

max = R[i]; indexH = i; } } cout << "The highest rainfall is " << max << " for " << M[indexH] << endl; }

int main() {

int x = 12; weather months[SIZE]; getinfo(months); Averagetemp(months, x); Totalrain(months, x); Averagerain(months, x); }

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

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions