Answer:
#include <iostream>
using namespace std;
int main() {
int NUM_VALS;// Defining NUM_VALS for the array size..
cout<<"Please state the array size"<<endl;
cin>>NUM_VALS;// Inputting the array size..
int hourlyTemp[NUM_VALS]; // Declaring an array hourlyTemp of size n..
cout<<"Enter the array values"<<endl;
for(int i=0;i<NUM_VALS;i++)
cin>>hourlyTemp[i];// Collecting hourlyTemp inputs
for(int i=0;i<NUM_VALS;i++) // Loop to traverse the array..
{
if(i!=NUM_VALS-1)
cout<<hourlyTemp[i]<<", ";// Print statement.
else
cout<<hourlyTemp[i];// Print statement.
}
return 0;
}
Explanation:
I used the NUM_VALS variable to set the size of the hourlyTemp array. Initially, I ask the user for the array size and then gather the elements. To process the array, I iterate through it using a for loop and ensure that I check if it's not the last element. If it's not, I print it along with a comma and space.