Write a C++ program such that its execution will keep asking the user to enter a
ID: 3641911 • Letter: W
Question
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.
NOTE (added on 25/3): If you enter 3 for start and 9 for finish, then the above formula for the subtotal becomes
32 + 42 + 52 + 62 + 72 + 82 + 92
which is 280. The following is the screenshot of one possible execution session (and your implementation may of course differ):
NOTE:
Enter integers for start and finish in pairs until
start > finish, which terminates the program
or when EOF or an invalid input has been made.
Enter start and finish -> 3 9
Enter start and finish -> 1 5
Enter start and finish -> 0 -1
TOTAL = 335
AVERAGE = 167.5
where numbers in this color are the user input.
Explanation / Answer
I hope this is clear and you understand the code, if not feel free to msg me here on cramster. #include //so we can format output #include using namespace std; int sum(int start, int end) { int sum=0; for(start;start> start >> end; if(startRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.