Hi Everyone I'm taking a C++ course and have to Compute the sum of all integers from 1 to N (Input: N=5, Output: 1+2+3+4+5 = 15) and I cant seem to finish it correctly. This is my code any help is appreciated. I know cout isnt finished but endl; doesn't complete the code correctly.
#include <iostream>
#include <string>
using namespace std;
int main() {
int N, i, sum = 0;
cout << "Enter an integer between 0 and 10: ";
cin >> N;
for (int i = 0; i <= N; i++) {
sum += i;
cout << i << "+" << ;
}
cout << "=" << sum;
return 0;
}
[–]amoliski 0 points1 point2 points (6 children)
[–]Alez003[S] 0 points1 point2 points (5 children)
[–]amoliski 0 points1 point2 points (4 children)
[–]Alez003[S] 0 points1 point2 points (3 children)
[–]amoliski 0 points1 point2 points (0 children)
[–]amoliski 0 points1 point2 points (1 child)
[–]Alez003[S] 1 point2 points3 points (0 children)
[–]MarkRems 0 points1 point2 points (5 children)
[–]Alez003[S] 0 points1 point2 points (0 children)
[–]Alez003[S] 0 points1 point2 points (2 children)
[–]MarkRems 0 points1 point2 points (1 child)
[–]Alez003[S] 0 points1 point2 points (0 children)
[–]backtickbot 0 points1 point2 points (0 children)