- #1
needOfHelpCMath
- 72
- 0
I don't understand how it able to skip one element to the other in order to multiply the numbers by 2. It be helpful if anyone can explain.Double any element's value that is less than minVal. Ex: If minVal = 10, then dataPoints = {2, 12, 9, 20} becomes {4, 12, 18, 20}.
✖ Testing minVal = 10 and dataPoints = {2, 12, 9, 20}
Expected output: 4 12 18 20
Your output: 4 24 18 40
Tests aborted.
Code:
#include <iostream>
#include <vector>
using namespace std;
int main() {
const int NUM_POINTS = 4;
vector<int> dataPoints(NUM_POINTS);
int minVal = 0;
int i = 0;
dataPoints.at(0) = 2;
dataPoints.at(1) = 12;
dataPoints.at(2) = 9;
dataPoints.at(3) = 20;
minVal = 10;
/* Your solution goes here */
for(i = 0; i < NUM_POINTS; ++i) {
dataPoints.at(i)= dataPoints.at(i) * 2;
}
for (i = 0; i < NUM_POINTS; ++i) {
cout << dataPoints.at(i) << " " ;
}
cout << endl;
return 0;
}
Expected output: 4 12 18 20
Your output: 4 24 18 40
Tests aborted.