10 is an odd number

When I run this code, I get
"The product of 5 and 2 is 10 and is odd. The sum of 5 and 2 is 7 and is odd." Which obviously is not correct since 10 is not odd, it is even. How can I fix this?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#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;
   
    if ( num % 2 == 0 )
    {
     cout << "The product of " << num << " and " << num2 << " is " << num*num2 << " and is even." << endl;
     cout << "The sum of " << num << " and " << num2 << " is " << num+num2 << " and is even." << endl;
    } 
 
    else
    {
     cout << "The product of " << num << " and " << num2 << " is " << num*num2 << " and is odd." << endl;
     cout << "The sum of " << num << " and " << num2 << " is " << num+num2 << " and is odd." << endl;   
    } 
    return (0);
} 


Last edited on
num is the first number entered. That is the only number who's odd/evenness you check.
I assume this is what u wanna do... :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#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;
    
    int sum,product;
    sum=num+num2;
    product=num*num2;

    if ( sum % 2 == 0 )
    {
     cout << "The sum of " << num << " and " << num2 << " is " << sum << "       and is even." << endl;
    } 
 
    else
    {
     cout << "The sum of " << num << " and " << num2 << " is " << sum << " and is odd." << endl;   
    } 

     if ( product % 2 == 0 )
    {
     cout << "The product of " << num << " and " << num2 << " is " << product << " and is even." << endl;
    } 
 
    else
    {
     cout << "The product of " << num << " and " << num2 << " is " << product << " and is odd." << endl;
    } 
    return (0);
}
Topic archived. No new replies allowed.