cout << "--------------------------------------------------------------------" << endl;
cout << "This program will sum up from 0 to the number user entered." << endl;
cout << "--------------------------------------------------------------------" << endl;
cout << "Please enter a whole numer: ";
cin >> n;
system ( "cls" );
for ( i = 1;i <= n;i++ )
{
sum = sum + i;
if ( i < n )
{
cout << i << " + ";
}
}
cout << " = " << sum << endl;
cout << endl;
cout << "The number you entered is: " << n << endl;
cout << "You ran the loop " << n << " times" << endl;
cout << "The total added up from 0 to " << n << " is: " << sum << endl;
#include <iostream>
usingnamespace std;
int main () {
int i, n;
int sum = 0;
cout << "--------------------------------------------------------------------" << endl;
cout << "This program will sum up from 0 to the number user entered." << endl;
cout << "--------------------------------------------------------------------" << endl;
cout << "Please enter a whole numer: ";
cin >> n;
for ( i = 1;i < n;i++ ) {
sum += i;
cout << i << " + ";
}
sum += n;
cout << n;
cout << " = " << sum << endl;
cout << endl;
cout << "The number you entered is: " << n << endl;
cout << "You ran the loop " << n << " times" << endl;
cout << "The total added up from 0 to " << n << " is: " << sum << endl;
return 0;
}
This works. Just loop until the last one and then custom-cout it without the plus sign.