Guest User

Untitled

a guest
Jan 20th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. //Andrew lohr
  2. //Assignment 4
  3.  
  4. #include<iostream>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. int lownum, highnum,oddnum,sum=0;
  11.  
  12. cout<<"Enter a number, then another number greater than it.";
  13. cin>>lownum;
  14. cin>>highnum;
  15. cout<<"The odd numbers between the two numbers are: ";
  16.  
  17.  
  18. lownum++;
  19. for(int i = lownum; i < highnum; i++)
  20. {
  21. if(lownum % 2 != 0)
  22. {
  23. cout<<lownum<<" ";
  24. lownum++;
  25. }
  26. else
  27. {
  28. sum = lownum+sum;
  29. lownum++;
  30. }
  31. }
  32.  
  33. cout<<"\nThe sum of all the even integers is: " <<sum;
  34. system("pause>nul");
  35. }
  36.  
  37. Enter a number, then another number greater than it.24
  38. 48
  39. The odd numbers between the two numbers are: 25 27 29 31 33 35 37 39 41 43 45 47
  40.  
  41. The sum of all the even integers is: 396
  42. ------
  43. Enter a number, then another number greater than it.17
  44. 40
  45. The odd numbers between the two numbers are: 19 21 23 25 27 29 31 33 35 37 39
  46. The sum of all the even integers is: 308
  47. ------
  48. Enter a number, then another number greater than it.24
  49. 47
  50. The odd numbers between the two numbers are: 25 27 29 31 33 35 37 39 41 43 45
  51. The sum of all the even integers is: 396
  52. ------
  53. Enter a number, then another number greater than it.17
  54. 47
  55. The odd numbers between the two numbers are: 19 21 23 25 27 29 31 33 35 37 39 41
  56. 43 45
  57. The sum of all the even integers is: 480
Add Comment
Please, Sign In to add comment