Guest User

Untitled

a guest
Jul 18th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int num1, num2, input1, input2, subtotal, average, total, count;
  7. input1 = 0;
  8. input2 = 0;
  9. num1 = 0;
  10. num2 = 0;
  11. subtotal = 0;
  12. total = 0;
  13. count = 0;
  14.  
  15.  
  16. cout << "Enter integers for start and finish in pairs until start > finish";
  17. cout << ", which terminates the program or when EOF or an invalid input";
  18. cout << "has been made.\n\n";
  19. while (input1 <= input2)
  20. {
  21. cout << "Enter start and finish integers -> ";
  22. cin >> input1 >> input2;
  23. count++;
  24. if (cin.eof())
  25. {
  26. cout << "\nEOF...\n";
  27. average = (total / (count - 1));
  28. cout << "\nTOTAL = " << total << endl;
  29. cout << "AVERAGE = " << average << endl << endl;
  30. break;
  31. }
  32. if (cin.fail())
  33. {
  34. cout << "\nFAIL...\n";
  35. average = (total / (count - 1));
  36. cout << "\nTOTAL = " << total << endl;
  37. cout << "AVERAGE = " << average << endl << endl;
  38. break;
  39. }
  40. num1 = input1;
  41. num2 = input2;
  42. while (num1 <= num2)
  43. {
  44. subtotal = (num1 * num1);
  45. total = subtotal + total;
  46. num1++;
  47. }
  48. }
  49. if (input1 > input2)
  50. {
  51. average = (total / (count - 1));
  52. cout << "\nTOTAL = " << total << endl;
  53. cout << "AVERAGE = " << average << endl << endl;
  54. }
  55. system("pause");
  56.  
  57. return 0;
  58. }
Add Comment
Please, Sign In to add comment