Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int num1, num2, input1, input2, subtotal, average, total, count;
- input1 = 0;
- input2 = 0;
- num1 = 0;
- num2 = 0;
- subtotal = 0;
- total = 0;
- count = 0;
- cout << "Enter integers for start and finish in pairs until start > finish";
- cout << ", which terminates the program or when EOF or an invalid input";
- cout << "has been made.\n\n";
- while (input1 <= input2)
- {
- cout << "Enter start and finish integers -> ";
- cin >> input1 >> input2;
- count++;
- if (cin.eof())
- {
- cout << "\nEOF...\n";
- average = (total / (count - 1));
- cout << "\nTOTAL = " << total << endl;
- cout << "AVERAGE = " << average << endl << endl;
- break;
- }
- if (cin.fail())
- {
- cout << "\nFAIL...\n";
- average = (total / (count - 1));
- cout << "\nTOTAL = " << total << endl;
- cout << "AVERAGE = " << average << endl << endl;
- break;
- }
- num1 = input1;
- num2 = input2;
- while (num1 <= num2)
- {
- subtotal = (num1 * num1);
- total = subtotal + total;
- num1++;
- }
- }
- if (input1 > input2)
- {
- average = (total / (count - 1));
- cout << "\nTOTAL = " << total << endl;
- cout << "AVERAGE = " << average << endl << endl;
- }
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment