Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Programmr: Addition
- Jarod Beaumariage 4-27-2017*/
- #include <iostream>
- #include <string>
- #include <windows.h>
- #include <iomanip>
- #include "MyConsole.h"
- using namespace std;
- int Intro()
- {
- cout << "This program takes a list of integers that you enter and tells you the" << endl;
- cout << "sum of the negative integers, sum of the positive even integers, and sum" << endl;
- cout << "of the positive odd integers. Press enter when you are ready to start.";
- cin.ignore();
- ClearScreen();
- return 0;
- }
- //=========================================================================================
- void addition(int in, int &negative_sum, int &even_positive_sum, int &odd_positive_sum)
- {
- if(in < 0)
- {
- negative_sum += in;
- }
- if(in > 0 && in % 2 == 0)
- {
- even_positive_sum += in;
- }
- else if(in > 0 && in % 2 != 0)
- {
- odd_positive_sum += in;
- }
- }
- //=====================================================================================================
- void repeat(char &again)
- {
- cout << endl;
- cout << "Would you like to run the program again? Enter either 'y' or 'n': ";
- cin >> again;
- ClearScreen();
- while(again != 'y' && again != 'n')
- {
- cout << "Error! Please enter either 'y' or 'n': ";
- cin >> again;
- ClearScreen();
- }
- }
- //=====================================================================================================
- int main()
- {
- int input, negative = 0, even = 0, odd = 0;
- char rep;
- Intro();
- do
- {
- cout << "Enter a list of positive and/or negative integers (Enter 0 to stop): " << endl;
- do
- {
- cin >> input;
- addition(input, negative, even, odd);
- }while(input != 0);
- ClearScreen();
- SetColor(4);
- cout << "The sum of the negative numbers is " << negative << "." << endl;
- SetColor(5);
- cout << "The sum of the positive odd numbers is " << odd << "." << endl;
- SetColor(2);
- cout << "The sum of the positive even numbers is " << even << "." << endl;
- SetColor(7);
- repeat(rep);
- //Reset values before running again
- negative = 0, even = 0, odd = 0;
- }while(rep != 'n');
- cout << "Ok, have a great day!";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement