Writing a program that determines if the product is even or odd.

Write a program that asks the user for two integers. The program will then multiply the two numbers and determine whether the product is even or odd. Next, add the two numbers and output whether the sum is even or odd. The program should look like this:
Please enter an integer: 5 [entered]
Please enter another integer: 2 [entered]
The product of 5 and 2 is 10 and is even.
The sum of 5 and 2 is 7 and is odd.

So i tried this, I think im suppose to use "if else" but not sure how to do it.

#include<iostream>
using namespace std;
int main ()

int num;
cout << "Please enter an integer: ";
cin >> num;

int num2;
cout << "Please enter another integer: ";
cin >> num2;

cout << "The product of " << num << "and" << num2 << "is" << num*num2 << endl;
cout << "The sum of " << num << "and" << num2 << "is" << num+num2 << endl;

if (even){
Use the % operator.

1
2
3
4
if (some_number % 2 == 0)
{
  // number is even
}
Its not that hard to type "if statements c++" on google. If you are more of a visual learner it is just as simple typing it on youtube.

http://www.cprogramming.com/tutorial/lesson2.html

As for determening even or odd. You can use the modulus operator.

http://www.cprogramming.com/tutorial/modulus.html

Oh and of course welcome to the forum. Please use code tags for all of your code - http://www.cplusplus.com/articles/jEywvCM9/
Last edited on
Topic archived. No new replies allowed.