From daa6f360d48c237de0da4f06ea6e8edcaa48f28d Mon Sep 17 00:00:00 2001 From: Sonny Li Date: Wed, 27 Feb 2019 12:50:26 -0500 Subject: [PATCH] Create oddeven.cpp --- 5-vectors/oddeven.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 5-vectors/oddeven.cpp diff --git a/5-vectors/oddeven.cpp b/5-vectors/oddeven.cpp new file mode 100644 index 0000000..785db74 --- /dev/null +++ b/5-vectors/oddeven.cpp @@ -0,0 +1,30 @@ +#include +#include + +int main() { + + int total_even = 0; + int product_odd = 1; + + std::vector vector = {2, 4, 3, 6, 1}; + + for (int i = 0; i < vector.size(); i++) { + + if (vector[i] % 2 == 0) { + + total_even = total_even + vector[i]; + + } else { + + product_odd = product_odd * vector[i]; + + } + + } + + std::cout << "Sum of even numbers is " << total_even << "\n"; + std::cout << "Product of odd numbers is " << product_odd << "\n"; + + return 0; + +}