- #1
ineedhelpnow
- 651
- 0
Write a for loop to print all NUM_VALS elements of vector courseGrades, following each with a space (including the last). Print forwards, then backwards. End with newline. Ex: If courseGrades = {7, 9, 11, 10}, print:
7 9 11 10
10 11 9 7
Hint: Use two for loops. Second loop starts with i = NUMVALS - 1.Sample program:
this is what i came up with
what should my condition be for the second loop?
7 9 11 10
10 11 9 7
Hint: Use two for loops. Second loop starts with i = NUMVALS - 1.Sample program:
Code:
#include <iostream>
#include <vector>
using namespace std;
int main() {
const int NUM_VALS = 4;
vector<int> courseGrades(NUM_VALS);
int i = 0;
courseGrades.at(0) = 7;
courseGrades.at(1) = 9;
courseGrades.at(2) = 11;
courseGrades.at(3) = 10;
<STUDENT CODE>
return 0;
}
Code:
for(i=0;i<NUM_VALS;++i) {
cout<<courseGrades.at(i)<<" ";
}
cout<<endl;
for(i=NUM_VALS-1;?;++i){
cout<<courseGrades.at(i)<<" ";
}
cout<<endl;