if(num % 2 == 0)
{
//number is even
}
else
{
//number is odd
}
Members here are more inclined to help once you've showed some of the code you've already started (for the sake of not doing homework for you, but to help you along with it instead).
int main()
{
int numbers[] = {4,3,2,1,6};
int sum_evens(0), sum_odds(0);
for (int n = 0; n < sizeof(numbers)/sizeof(int); ++n)
{
if (numbers[n] %2)
sum_odds += numbers[n];
else
sum_evens += numbers[n];
}
return 0;
}
if your talking about op vlad, he said "this will be the output". ie thats the final product. if your talking about aj, your not supposed to enter numbers anywhere
Come on, you have to do somthing yourself. You can either enter the input in the program argument list or you can user user input while the program is running. Maybe, you need to learn how to do this yourself!
I'm new here sir. And I'm new in c++ so I want to learn about that. I cant even make it see this.
#include <iostream>
using namespace std;
int main ()
{
int num1;
int num2;
int num3;
int even;
int odd;
if (num1,num2,num3% 2 == 0)
cout << "Enter number: ";
cin >> num1;
cout << num1<<" is an even number"<<endl;
cout << "Enter number: ";
cin >> num2;
cout << num2<<" is an even number"<<endl;
cout << "Enter number: ";
cin >> num3;
cout << num3<<" is an even number"<<endl;
if (num1+num2+num3 % 2 == 0)
{
even = num1 + num2 + num3;
cout << "The sum of even: "<<even;
}
else (num1+num2+num3 % 2 == 0);
{
odd = num1 + num2 + num3;
cout << "The sum of odd: "<<odd;
}
//
// oddeven.cpp
//
// take numeric input from user, store in vector,
// stop adding numbers to array when non-numeric input
// encountered. Add up all even and odd numbers, and
// display the sum of each to the user.
//
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
usingnamespace std;
//
// Get the numbers from the user
// and assign to array. Keeps getting
// user input until user enters a non-
// numeric value, then exit:
//
void get_numbers(vector<int>& numbers)
{
while (true)
{
int number;
string input;
cout << "Enter Number: ";
getline(cin,input);
stringstream ss(input);
if (ss >>number)
numbers.push_back(number);
elsebreak;
}
}
//
// Calculates total sum of even numbers
// and total sum of odd numbers in array,
// and display to user:
//
void output_results(vector<int>& numbers)
{
int sum_evens(0), sum_odds(0);
for (int n = 0; n < numbers.size(); ++n)
{
if (numbers[n] %2)
sum_odds += numbers[n];
else
sum_evens += numbers[n];
}
cout << "The sum of all even numbers is: " << sum_evens << endl;
cout << "The sum of all odd numbers is: " << sum_odds << endl;
}
//
// Entry point to program:
//
int main(int argc, constchar * argv[])
{
vector<int> numbers;
get_numbers(numbers);
output_results(numbers);
return 0;
}