60 688
Assignments Done
97,9%
Successfully Done
In April 2018

Answer to Question #2771 in C++ for will

Question #2771
I cant seem to get this programm to run and i dunno what the output will be can some one help me ?
the code is
vector <int> myinventory(4);
myinventory[0] = 2;
for(int i = 1; i <= 3; i++)
& {
& & myinventory[i] = 2*myinventory[i - 1];
& & }
myinventory.push_back(34);
for (int i = 0; i< myinventory.size();i++)
& & {
& & & & cout << myinventory[i] <<" ";=""
& & }

Expert's answer
1) First you should define variable as follows:

& vector<int> myinventory(4);
Instead of
vector myinventory(4);

2) the last line
cout<<myinventory[i] <<" ";=""
& contains an error. It should be like this:
cout<<myinventory[i] <<"; ";

Corrected program:

vector<int> myinventory(4);
myinventory[0] = 2;
for(int i = 1; i <= 3; i++)
{
& myinventory[i] = 2*myinventory[i - 1];
}
myinventory.push_back(34);
for (unsigned int i = 0; i<myinventory.size();i++)
{
cout<<myinventory[i] <<"; ";
};

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions