Purpose. Learn how to search an array, to count matching values. Requirements. Modify Exercise 11.2's myCity3.cpp, adding loops to count how many times the high temperature occurs and how may times the low temperature occurs. Output the results. Name the new program myCity4.cpp. Here are the changes from v.3.0: 1. Prompt the user for the 5 temperatures. 2. Count the number of times the high and low temperatures occur. In the output say "once" or "one time" if the count is only one. Otherwise say something like "2 times". 3. Use additional variables to avoid typing the city name and the days more than once each. 4. Do not output the source. Program I/O. Input console input of 5 daily high temperatures. Output same as v.3.0, adding counts Example. The output should look something like: Enter the high for San Jose on Wednesday, Aug 25: 79 Thursday, Aug 26: 80 Enter the high for San Jose on Enter the high for San Jose on Friday, Aug 27: 80 Enter the high for San Jose on Saturday, Aug 28: 76 Enter the high for San Jose on Sunday, Aug 29: 71 San Jose forecast high temperatures: Wednesday, Aug 25, 79 degrees Thursday, Aug 26, 80 degrees Friday, Aug 27, 80 degrees Saturday, Aug 28, 76 degrees Sunday, Aug 29, 71 degrees The high for the week is 80 degrees, occurring 2 times The low for the week is 71 degrees, occurring once
#include <iostream>
using namespace std;
int main()
{
cout << "San Jose, California forecast high temperatures: " << endl;
int temp[5]= {86,81,73,77,79};
cout << "Monday, September 26, " << temp[0] << " degrees" << endl;
cout << "Tuesday, September 27, " << temp[1] << " degrees" << endl;
cout << "Wednesday, September 28, " << temp[2] << " degrees" << endl;
cout << "Thursday, September 29, " << temp[3] << " degrees" << endl;
cout << "Friday, September 30, " << temp[4] << " degrees" << endl;
int minimum = temp[0];
int maximum = temp[0];
for (int i =0; i<5; i++)
{
if (minimum > temp[i])
{
minimum = temp[i];
}
if (maximum < temp[i])
{
maximum = temp[i];
}
}
cout << endl;
cout << "The high for the week is " << maximum << endl;
cout << "The low for the week is " << minimum << endl;
cout << endl;
cout << "source: Weather.com " << endl;
}
// I've attached the (city3.cpp) source code that needs to be modified. Please pay attention to the instruction. If possible don't publish my source code please.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 1 images
When we output the high or low temperature if it's occuring once it should say occuring "once" instead of 1 time. also, the program must use additional variables to avoid typing the city name and the days more than once each.