Answer:
#include <iostream>
using namespace std;
int main() {
int start, stop, evenSum=0, oddSum=0;
cout << "Enter an integer to start: ";
cin >> start;
cout << "Enter an integer to stop: ";
cin >> stop;
for(int i = start; i <= stop; i++){
if (i % 2 == 0){
evenSum += i;
}
else{
oddSum += i;
}
}
cout << "Sum of odd numbers between " << start << " and " << stop << " is: " << oddSum<< endl;
cout << "Sum of even numbers between " << start << " and " << stop << " is: " << evenSum<< endl;
return 0;
}
Important: Please read explanation below
Step-by-step explanation:
My program computes the sums for odd and even numbers between start number and stop number inclusive.
For example if you enter start = 1 and stop = 8 it will compute odd sum as 1 + 3 + 5 + 7 = 16 and even sum as 2 + 4 + 8= 16
If you want to omit the start and stop numbers in the computation, change the for loop to the following:
for (int i = start + 1; i < stop; i++)
If you want to include the start but omit the end number,
for (int i = start; i < stop;i++)
Well, you get the drift