Advertisement
jaybeau21

Addition

Apr 28th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. /*Programmr: Addition
  2. Jarod Beaumariage 4-27-2017*/
  3.  
  4. #include <iostream>
  5. #include <string>
  6. #include <windows.h>
  7. #include <iomanip>
  8. #include "MyConsole.h"
  9.  
  10. using namespace std;
  11.  
  12. int Intro()
  13. {
  14. cout << "This program takes a list of integers that you enter and tells you the" << endl;
  15. cout << "sum of the negative integers, sum of the positive even integers, and sum" << endl;
  16. cout << "of the positive odd integers. Press enter when you are ready to start.";
  17.  
  18. cin.ignore();
  19. ClearScreen();
  20.  
  21. return 0;
  22. }
  23.  
  24. //=========================================================================================
  25.  
  26. void addition(int in, int &negative_sum, int &even_positive_sum, int &odd_positive_sum)
  27. {
  28. if(in < 0)
  29. {
  30. negative_sum += in;
  31. }
  32. if(in > 0 && in % 2 == 0)
  33. {
  34. even_positive_sum += in;
  35. }
  36. else if(in > 0 && in % 2 != 0)
  37. {
  38. odd_positive_sum += in;
  39. }
  40. }
  41.  
  42. //=====================================================================================================
  43.  
  44. void repeat(char &again)
  45. {
  46. cout << endl;
  47. cout << "Would you like to run the program again? Enter either 'y' or 'n': ";
  48. cin >> again;
  49. ClearScreen();
  50.  
  51. while(again != 'y' && again != 'n')
  52. {
  53. cout << "Error! Please enter either 'y' or 'n': ";
  54. cin >> again;
  55. ClearScreen();
  56. }
  57. }
  58.  
  59. //=====================================================================================================
  60.  
  61. int main()
  62. {
  63. int input, negative = 0, even = 0, odd = 0;
  64. char rep;
  65.  
  66. Intro();
  67.  
  68. do
  69. {
  70. cout << "Enter a list of positive and/or negative integers (Enter 0 to stop): " << endl;
  71.  
  72. do
  73. {
  74. cin >> input;
  75.  
  76. addition(input, negative, even, odd);
  77. }while(input != 0);
  78.  
  79. ClearScreen();
  80.  
  81. SetColor(4);
  82. cout << "The sum of the negative numbers is " << negative << "." << endl;
  83. SetColor(5);
  84. cout << "The sum of the positive odd numbers is " << odd << "." << endl;
  85. SetColor(2);
  86. cout << "The sum of the positive even numbers is " << even << "." << endl;
  87. SetColor(7);
  88.  
  89. repeat(rep);
  90.  
  91. //Reset values before running again
  92. negative = 0, even = 0, odd = 0;
  93.  
  94. }while(rep != 'n');
  95.  
  96. cout << "Ok, have a great day!";
  97.  
  98. return 0;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement