5.5.1: Making and using vectors. C++ ONLY FORZYBOOKS
Integers are read from input and stored into a vector until -1is read. For each vector element E, output the sum between E andthe vector's last element. End each number with a newline.
Ex: If the input is 2 11 -15 4 -1, the vector's last element is4. Thus, the output is:
Note:
MY CODE C++ :
#include <iostream>#include <vector>using namespace std;
int main() { int i; vector<int> integerVector; int value;
cin >> value; while (value != -1) { integerVector.push_back(value); cin >> value; }
// Output Logic goes here
// storing the last element in avariable int last_element = integerVector.back(); cout<<"Output is :"<<endl;
// iterating through the vector for(inti=0;i<integerVector.size()+1;i++){ // multiplying the elementsof the vector // with the last element ofthe vector cout<<integerVector*last_element<<endl; }
return 0;}
MY ERRORS: NEED HELP CLEARING ERRORS
For input 2 11-154-1, the vector elements are 2, 11, -15, and 4. The last element, 4, is added to 2 11, -15, and 4, respectively. The results are 6, 15, -11, and 8. Each result is printed on a new line. Not all tests passed. X 1: Compare output A Output differs. See highlights below. Special character legend Input Your output Expected output Input Your output Expected output X 2: Compare output A Output differs. See highlights below. Special character legend X 3: Compare output Input Expected output X 4: Compare output A Input Output differs. See highlights below. Special character legend 2 11 -15 4 -1 Expected output Output is : 84 44 -60 X5: Compare output 16 0 6 15 -11 8 Your output 45 20 254 Input Your output -2 -8 6 -1 Expected output Output is : -12 -48 364 04 4 -2 12 Output differs. See highlights below. Special character legend 11 -7 9 4 5 1 Output is : 554 -35 16 -2 14 -21@ Your output -45 39 -27 9 10 12 -2 -7 -15 13 -9 3 -1 Output is : 36 -6 9 O Output differs. See highlights below. Special character legend 15 1 -4 -12 16 6 -2 2-1 Output is : -4 4e ០ម 0 4
5.5.1: Making and using vectors. C++ ONLY FOR ZYBOOKS Integers are read from input and stored into a vector until -1 is
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am