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

in this c++ program how can I get hourly temperatures to print in this format Ho

ID: 3794285 • Letter: I

Question

in this c++ program how can I get hourly temperatures to print in this format
Hour.                Temperature
00:00                 ?
01:00                 ?
02:00
........
22:00
23:00

void GetTemperatures(array<int, 23>&Temperatures)
{
int CurrentTemp = 0;
for (int i = 0; i < 23; i++)
{
  cout << "Enter hourly temperature "<<(i+1)<<":";
  cin >> Temperatures[i];
  while ((Temperatures[i] > 130) || (Temperatures[i] < -50))
  {
   cout << "Out of range-Try Again";
   --i;
  }
  
}
}

Explanation / Answer

For the desired result, your function must look like this:

void GetTemperatures(array<int, 24>&Temperatures)
{
int CurrentTemp = 0;
for (int i = 0; i < 24; i++)
{
cout << "Enter hourly temperature "<<(i+1)<<":";
cin >> Temperatures[i];
if ((Temperatures[i] > 130) || (Temperatures[i] < -50))
{
cout << "Out of range-Try Again";
--i;
}

}//end of for loop

//printing the temperature
cout<<"Hour. Temperature ";
for(int i=0;i<24;i++)
{
printf("%2d:00 %d ",i+1,Temperatures[i]);
}
}//end of function

Hope it helps, do comment in case of any query.