Write a C++ program such that its execution will keep asking the user to enter a
ID: 3640969 • 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 subtotalstart2 + (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.
Explanation / Answer
I just saw that the program should keep asking the user for input if the input is correct, so I just modified the code little bit, now every time the user enters correct input it will calculate the total and ask again to enter new numbers. #include using namespace std; int main() { int firstNumber = 0; int lastNumber = 0; bool ValidInput = false; do { cout > firstNumber; cout > lastNumber; if (cin.fail() || lastNumberRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.