#include <iostream>
#include <iomanip>
usingnamespace std;
int main()
{
// declare variables
int number_1;
int number_2;
int sum = 0;
// ask for integers
cout << "Enter first integer: ";
cin >> number_1;
cout << "Enter second integer: ";
cin >> number_2;
// while statement to determine answer
while (number_1 <= number_2)
{
if(number_1 %2 != 0)
cout << number_1 << " is odd." << endl;
else
sum += number_1;
number_1++;
}
// display answers
cout << "The sum of all even numbers between " << number_1 << " and " << number_2 << " is " << sum << "." << endl;
cin.get();
}
At the end of the program it's suppose to display the sum of all even numbers between number_1 and number_2. Except instead of it reading what the user inputted as number_1, it reads a different number.
Example:
Enter first integer: 1
Enter second integer: 7
1 is odd.
3 is odd.
5 is odd.
7 is odd.
The sum of all even numbers between 8 and 7 is 12.