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

Write a program that inputs an integer greater than 0 and calculates the sum of

ID: 3651912 • Letter: W

Question

Write a program that inputs an integer greater than 0 and calculates the sum of the squares from 1 to that integer. For example, if the integer equals 4, the sum of the squares is 30 (1 + 4 + 9 + 16). The program should repeat this process until the user wants to quit. An input value less than or equal to 0 signals the end of the data.

Sample screen output:




Enter a number greater than 0 (less than 1 to quit): 4
The sum of the squares from 1 to 4 is 30
Enter a number greater than 0 (less than 1 to quit): 1
The sum of the squares from 1 to 1 is 1
Enter a number greater than 0 (less than 1 to quit): 0

Turn in your source code followed by one sample output similar to the sample given above.





I did attempt this program but could not get the logic of the equation or the loop particularly correct.

Can I get help? My incorrect source code is this:

#include<iostream>
#include<cstdlib>

using namespace std;

int main()
{

int value;
int sum=0;

cout<<" Enter a number greater than 0 (less than 1 to quit): ";
cin>>value;


while(value > 0)
{
if(value>=sum)

sum=sum^2;
cout<<"The sum of the squares from 1 to " << value << " is " << sum << " ";
break;
}



system("PAUSE");
return 0;
}

Explanation / Answer

#include #include using namespace std; int main() { int value=1; int sum=0; while(value > 0) { coutvalue; sum = 0; for(int i=1;i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote