Question: Write a for loop to print all NUM_VALS elements of array hourlyTemp. Separate elements with a comma and space. Ex: If hourlyTemp = {90, 92,

Write a for loop to print all NUM_VALS elements of array hourlyTemp. Separate elements with a comma and space. Ex: If hourlyTemp = {90, 92, 94, 95}, print:

90, 92, 94, 95 

Your code's output should end with the last element, without a subsequent comma, space, or newline.

CODE:

#include using namespace std;

int main() { const int NUM_VALS = 4; int hourlyTemp[NUM_VALS]; int i;

for (i = 0; i < NUM_VALS; ++i) { cin >> hourlyTemp[i]; }

/* Your solution goes here */ for (i = 0; i < NUM_VALS; ++i) { if(i==0) cout << hourlyTemp[i] << " " << endl; else cout << hourlyTemp[NUM_VALS - 1] << ", " << endl; }

need help its not working

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!