Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include <iostream> using namespace std int main() { int sum = 0; cout << \"This

ID: 3620050 • Letter: #

Question

#include <iostream>
using namespace std

int main()
{
int sum = 0;
cout << "This program will add all the integers between 1 and N." <<endl;
cout << "Please specify a positive integer N: ";
cin >> n;
if (n <= 0) //end program early if user submits negative number
{
cout << "Sorry, but you gave a negative number! This program will end." <<endl;
getchar();
getchar();
return 0;
}

//If user submits a nonnegative integer, use for loop to find sum
for (int i = 0; i <= n; i++)
sum = sum + i;

cout << "The sum of the first " << n << " integers is " << sum
<< "." << endl;

getchar();
getchar();
return 0;
}

Explanation / Answer

please rate - thanks very nice work see the comments, highlighted in red #include <iostream>
using namespace std;      //; missing

int main()
{
int sum = 0,n;          //n not declared
cout << "This program will add all the integers between 1 and N." <<endl;
cout << "Please specify a positive integer N: ";
cin >> n;
if (n <= 0) //end program early if user submits negative number
{
cout << "Sorry, but you gave a negative number! This program will end." <<endl;
getchar();
getchar();
return 0;
}

//If user submits a nonnegative integer, use for loop to find sum
for (int i = 0; i <= n; i++)
sum = sum + i;

cout << "The sum of the first " << n << " integers is " << sum
<< "." << endl;

getchar();
getchar();
return 0;
}