Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help with this C++ program Learning Objectives: Use of while loops to: Vali

ID: 3887053 • Letter: N

Question

Need help with this C++ program Learning Objectives: Use of while loops to: Validate user input. Determine the sum, count, min, highest and lowest of data values entered. Entering multiple values on one line with cout/cin. General Description: Write a program for processing temperature readings for a period of days. The program first asks the user to enter the number of days, validating the answer between 1 and 10 It then asks the user to enter the Hi and Low Temperatures for each day. Finally, it finds and prints the highest high, lowest low, average high and average low. It should also print the number of days the low temperature was below freezing (less than 32 degrees). As usual, the program should pause at the end. Note:alnumbers, including averages, may be integers. Examples of what this should look like: Enter number of days 1-10); 6 Enter Hi and Low for day 1: 44 33 Enter Hi and Low for day 2: 55 44 Enter Hi and Low for day 340 30 Enter Hi and Low for day 4: 31 28 Enter Hi and Low for day 5 44 33 Enter Hi and Low for day 6 48 38 The Highs: max = 55 avg = 43 The Lows : min = 28 avg = 34 Number of days below freezing: 2 Press any key to continue _

Explanation / Answer

#include <iostream.h>

using namespace std;

void requestInput(int & numOfDays;)

{

cout<<"enter number of days <1-10> :"<<endl ;

cin>>numOfDays;

}

int main()

{

cout<<"enter number of days <1-10> :"<<endl ;

int numOfDays;

requestInput(numOfDays);

if(numOfDays < 1 || numOfDays > 10)

{

cout<<"Invalid Entry . Try Again"<<endl ;

requestInput(numOfDays);

}

else

{

int Hi, Low, ;

int HiMax = Hi, LowMin = Low;

int HiSUm =0;

int LowSum = 0;

int countLessThanFreeze =0;

for( i =1 ; i<= (numOfDays); i++)

{

cout<<"enter Hi and Low for day %d"<<i<<endl ;

cin >>Hi >>Low;

if(Low < 32)

countLessThanFreeze++;

if(Hi > HiMax )

HiMax = Hi;

if(Low < LowMin)

LowMin = Low;

HiSUm = HiSUm + Hi;

LowSum = LowSum + Low;

  

}

cout<<"The High : max = %d avg = %d"<<HiMax<<(HiSUm/numOfDays)<<endl ;

cout<<"The Lows: min = %d avg = %d"<<LowMin <<(LowSum/numOfDays)<<endl ;

cout<<"Number of days below freezing %d"<<countLessThanFreeze<<endl ;

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote