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

Write a for loop to print all NUM_VALS elements of array hourlyTemp. Separate el

ID: 3601640 • Letter: W

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, 94, 95), print: 90, 92, 94, 95 Note that the last element is not followed by a comma, space, or newline #include 2 using namespace std; 1 test passed 4 int main 5 const int NUM-VALS = 4; 6 int hourlyTempNUM VALS]; All tests passed int i = 0; 9 hourlyTemp[0]=90; 10 hourlyTemp[1]=92; 11 hourlyTemp[2]=94; 12 hourlyTemp[3]=95; 13 14 Your solution goes here 15 16 cout

Explanation / Answer

#include <iostream>

using namespace std;

int main() {

const int NUM_VALS = 4;

int hourlyTemp[NUM_VALS] ;

int i = 0;

hourlyTemp[0] = 90;

hourlyTemp[1] = 92;

hourlyTemp[2] = 94;

hourlyTemp[3] = 95;

/* Your solution goes here */

for(i=0; i<NUM_VALS; i++){

if(i!=NUM_VALS-1)

cout<<hourlyTemp[i]<<", ";

else

cout<<hourlyTemp[i];  

}

cout<<endl;  

return 0;

}

Output:

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