fork download
  1. #include <iostream>
  2.  
  3. using std::cout;
  4. using std::endl;
  5. using std::cin;
  6.  
  7. int main()
  8. {
  9. int numb1, numb2;
  10. cout << "Type the two bounding integers: ";
  11. cin >> numb1 >> numb2;
  12. int total = 0;
  13. for(int i = numb1; i <= numb2; i += 2)
  14. {
  15. total += i;
  16. }
  17. cout << endl << "Total: " << total << endl;
  18. if (numb1 % 2 == 1) cout << "The total is not correct. Why? How can it be fixed?" << endl;
  19. return 0;
  20. }
Success #stdin #stdout 0s 2728KB
stdin
5 23
stdout
Type the two bounding integers: 
Total:  140
The total is not correct.  Why?  How can it be fixed?