It's my first time with C++.
i searched other question, but i couldn't solve my problem :(
I just want to print all of element of list and print sum.
But, i got some problem of char "+"
This is my code.
#include <iostream>
#include <list>
using namespace std;
int main() {
int count = 0, sum = 0;
list<int> square;
int n, m;
cout << "Please enter tow positive integers between M and N -> ";
cin >> m >> n;
while (m>=n) {
cout << "Please try agrin" << endl;
cin >> m >> n;
}
for (int i = 1; i <= n; i=i+1) {
/*cout << i << endl;*/
if (i*i >= m && i*i <= n) {
square.push_back(i*i);
count=count+1;
sum = sum + (i*i);
//cout << i << endl;
}
}
for (list<int>::iterator i = square.begin(); i != square.end(); ++i)
cout << *i << "+";
cout << "=" << sum;
return 0;
}
I got output like below.
16+25+36+49+64+81+100+=371
but i wanna get like below.
16+25+36+49+64+81+100=371
that has no "+" char at last element.
But i don't know how to do.
Is there any idea for this?