This was a difficult quiz for me, at first I didn\u00b4t know how to use arrays so I decide to use vectors, in the end..IT WORKS!!!!<\/p>\n
<\/p>\n
#include<\/a> <iostream><\/span>
#include<\/a> <vector><\/span>
using<\/span> namespace<\/span> std;
void<\/span> newline<\/span>(){
\u00a0 cout<<<\/span>endl;
}
double<\/span> sumsquares_list<\/span> (vector<<\/span>double<\/span>><\/span> vector){
\u00a0 double<\/span> a =<\/span> vector.size();
\u00a0 double<\/span> sum=<\/span>0<\/span>;
\u00a0 for<\/span>(double<\/span> i=<\/span>0<\/span>; i<<\/span>a; i++<\/span>){
\u00a0\u00a0\u00a0 sum=<\/span>sum+<\/span>(vector[i]*<\/span>vector[i]);
\u00a0 }
\u00a0 return<\/span> sum;
}
int<\/span> main<\/span> (){
\u00a0 double<\/span> x;
\u00a0 vector<<\/span>double<\/span>><\/span>vector (0<\/span>, 4<\/span>); \/\/You assign a size for your vector.<\/span>
\u00a0 cout<<<\/span>"Hi, I\u00b4m a calculator of the addition of squares of the numbers you\u00b4ll give me "<\/span><<<\/span>endl;
\u00a0 newline();
\u00a0 cout<<<\/span>"introduce the number (to stop introducing numbers write-->-42)"<\/span><<<\/span>endl;
\u00a0 newline();
\u00a0 cin>><\/span>x;
\u00a0 newline();
\u00a0 while<\/span>(x!=-<\/span>42<\/span>){
\u00a0\u00a0\u00a0 newline();
\u00a0\u00a0\u00a0 cout<<<\/span>"introduce the next number "<\/span><<<\/span>endl;
\u00a0\u00a0\u00a0 newline();
\u00a0 vector.push_back(x); \/\/You\u00b4re increasing the size of the vector<\/span>
\u00a0 cin>><\/span>x;
\u00a0 }
\u00a0 cout<<<\/span>"The result equals to "<\/span><<<\/span>sumsquares_list(vector)<<<\/span>endl;
\u00a0 return<\/span> 0<\/span>;
}
<\/pre>\n<\/div>\n\u00a0Here\u00b4s my code<\/p>\n
https:\/<\/wbr>\/<\/wbr>github.com\/<\/wbr>everibarra\/<\/wbr>TC101-C-\/<\/wbr>blob\/<\/wbr>master\/<\/wbr>Q8.cpp<\/a><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"\nThis was a difficult quiz for me, at first I didn´t know how to use arrays so I decide to use vectors, in the end..IT WORKS!!!!<\/p>\n
<\/p>\n
\n#include<\/a> <iostream><\/span>
#include<\/a> <vector><\/span>
using<\/span> namespace<\/span> std;
void<\/span> newline<\/span>(){
cout<<<\/span>endl;
}
double<\/span> sumsquares_list<\/span> (vector<<\/span>double<\/span>><\/span> vector){
double<\/span> a =<\/span> vector.size();
double<\/span> sum=<\/span>0<\/span>;
for<\/span>(double<\/span> i=<\/span>0<\/span>; i<<\/span>a; i++<\/span>){
sum=<\/span>sum+<\/span>(vector[i]*<\/span>vector[i]);
}
return<\/span> sum;
}
int<\/span> main<\/span> (){
double<\/span> x;
vector<<\/span>double<\/span>><\/span>vector (0<\/span>, 4<\/span>); \/\/You assign a size for your vector.<\/span>
cout<<<\/span>\"Hi, I´m a calculator of the addition of squares of the numbers you´ll give me \"<\/span><<<\/span>endl;
newline();
cout<<<\/span>\"introduce the number (to stop introducing numbers write-->-42)\"<\/span><<<\/span>endl;
newline();
cin>><\/span>x;
newline();
while<\/span>(x!=-<\/span>42<\/span>){
newline();
cout<<<\/span>\"introduce the next number \"<\/span><<<\/span>endl;
newline();
vector.push_back(x); \/\/You´re increasing the size of the vector<\/span>
cin>><\/span>x;
}
cout<<<\/span>\"The result equals to \"<\/span><<<\/span>sumsquares_list(vector)<<<\/span>endl;
return<\/span> 0<\/span>;
}
<\/pre>\n<\/div>\n Here´s my code<\/p>\n