Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Andrew lohr
- //Assignment 4
- #include<iostream>
- using namespace std;
- int main()
- {
- int lownum, highnum,oddnum,sum=0;
- cout<<"Enter a number, then another number greater than it.";
- cin>>lownum;
- cin>>highnum;
- cout<<"The odd numbers between the two numbers are: ";
- lownum++;
- for(int i = lownum; i < highnum; i++)
- {
- if(lownum % 2 != 0)
- {
- cout<<lownum<<" ";
- lownum++;
- }
- else
- {
- sum = lownum+sum;
- lownum++;
- }
- }
- cout<<"\nThe sum of all the even integers is: " <<sum;
- system("pause>nul");
- }
- Enter a number, then another number greater than it.24
- 48
- The odd numbers between the two numbers are: 25 27 29 31 33 35 37 39 41 43 45 47
- The sum of all the even integers is: 396
- ------
- Enter a number, then another number greater than it.17
- 40
- The odd numbers between the two numbers are: 19 21 23 25 27 29 31 33 35 37 39
- The sum of all the even integers is: 308
- ------
- Enter a number, then another number greater than it.24
- 47
- The odd numbers between the two numbers are: 25 27 29 31 33 35 37 39 41 43 45
- The sum of all the even integers is: 396
- ------
- Enter a number, then another number greater than it.17
- 47
- The odd numbers between the two numbers are: 19 21 23 25 27 29 31 33 35 37 39 41
- 43 45
- The sum of all the even integers is: 480
Add Comment
Please, Sign In to add comment