#include <iostream>
using namespace std;
int main()
{
int num1, num2,r,i;
cout<<"Enter a start: ";
cin>>num1;
cout<<"Enter an end: ";
cin>>num2;
cout<<"\\\\ODD NUMBERS\\";
for(i=num1; i<=num2; i++){
r=i%2;
if(r==1)
cout<<" "<<i;
}
cout<<"\\EVEN NUMBERS\\";
for(i=num1; i<=num2; i++){
r=i%2;
if(r==0)
cout<<" "<<i;
}
if(num1>num2){
cout<<"ERROR! Starting Number is GREATER THAN the Ending Number!!!";
return 0;
}
}
Using while loop, do while and for loop write a C++ program that lets you input a starting and ending integer (range) then display all the odd integers and the even integers within the range then compute the sum of each set of integers.:
If the starting number is greater than ending number, the program should display “ERROR! Starting Number is GREATER THAN the Ending Number!!!”.
Sample output:
Enter a start: 1
Enter an end: 10
ODD NUMBERS
1 3 5 7 9 Sum: 25
EVEN NUMBERS
2 4 6 8 10 Sum: 30
the attached pic has been my progress so far. please help me reach the expected output.