0

Write a C++ program such that its execution will keep asking the user to enter a pair of integers, start and finish, and will terminate when either start>finish, or EOF or an invalid input has been encountered. Every time a new pair of integers start and finish are read, the program will first calculate the subtotal

start2 + (start+1)2 + (start+2)2 + ... + (finish-1)2 + finish2

and then add the subtotal to the total. Before the program terminates, it should display the accumulated total and the average of all the subtotals. Also draw the IPO diagram for this problem, and write your solution algorithm in pseudo code.

so far i've got this

```
#include <iostream>
// #include <string>
using namespace std;
int main()
{
int start, finish;
do
{
cout << "Enter the START number: ";
if( ! (cin >> start) || start < 0) { //Checks to see if the inputted value is invalid or less than 0
return 0; //terminates program
}
cout << "Enter the FINISH number: ";
if( ! (cin >> finish) || finish < 0) { //Checks to see if the inputted value is invalid or less than 0
return 0; //terminates program
}
//declare total, average
double total; double average;
//calculate total
total = start + finish;
//calculate average
average = total/2.0;
//display total
cout <<"Total:";cout << total << endl;
cout <<"Average:";cout << average << endl;
cout << endl << endl;
}
while (start < finish);
system("pause");
return 0;
}
```