5.5.1: Making and using vectors. C++ ONLY FOR ZYBOOKS Integers are read from input and stored into a vector until -1 is

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

5.5.1: Making and using vectors. C++ ONLY FOR ZYBOOKS Integers are read from input and stored into a vector until -1 is

Post by answerhappygod »

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

5 5 1 Making And Using Vectors C Only For Zybooks Integers Are Read From Input And Stored Into A Vector Until 1 Is 1
5 5 1 Making And Using Vectors C Only For Zybooks Integers Are Read From Input And Stored Into A Vector Until 1 Is 1 (29.66 KiB) Viewed 16 times
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
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply