- #1
ineedhelpnow
- 651
- 0
Write a for loop to print all NUM_VALS elements of vector 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.Sample program:
Below, do not type an entire program. Only type the portion indicated by the above instructions (and if a sample program is shown above, only type the <STUDENT CODE> portion.)
answer is
but is there any other way to write the if else statement?
90, 92, 94, 95
Note that the last element is not followed by a comma, space, or newline.Sample program:
Code:
#include <iostream>
#include <vector>
using namespace std;
int main() {
const int NUM_VALS = 4;
vector<int> hourlyTemp(NUM_VALS);
int i = 0;
hourlyTemp.at(0) = 90;
hourlyTemp.at(1) = 92;
hourlyTemp.at(2) = 94;
hourlyTemp.at(3) = 95;
<STUDENT CODE>
cout << endl;
return 0;
}
Below, do not type an entire program. Only type the portion indicated by the above instructions (and if a sample program is shown above, only type the <STUDENT CODE> portion.)
answer is
Code:
for(int i=0; i<NUM_VALS; i++)
{
if(i==0)
cout << hourlyTemp[i] ;
else cout <<", " << hourlyTemp[i];
}
but is there any other way to write the if else statement?