Hi everyone,
So, I have always had trouble in the pass with items like this, I could not understand vectors, arrays or anything similar to it, I just went through the first small review project of adding even and odd numbers, I added input for the user, as many as they would like to add, just look on some feedback on the code while I keep learner, Thanks in advance
And I apologize, I have no idea if there is any specific format to put in the code in here,
#include
#include
int main()
{
int user_number, evenTotal = 0, oddTotal = 1;
std::vector numbers;
std::cout << "Please enter a number to add, enter 0 to add your numbers: ";
std::cin >> user_number;
while (user_number != 0) {
numbers.push_back(user_number);
std::cout << "Please enter a number to add, enter 0 to add your numbers: ";
std::cin >> user_number;
}
for (int i = 0; i < numbers.size(); i++) {
if (numbers[i] % 2 == 0) {
evenTotal += numbers[i];
}
else {
oddTotal *= numbers[i];
}
}
std::cout << "Sum of even numbers is " << evenTotal << " \n";
std::cout << "Product of odd numbers is " << oddTotal << " \n";
}
edit: I had read the directions wrong and did not realized it was product of odd, fix it and repost it.