我遇到一个简单的程序有问题,它将乘以2个整数并打印输出,确定它是偶数还是奇数.它还将在开头添加2个整数输入,并在下一行中执行相同操作.乘法工作正常,如果产品是偶数或奇数,则显示.但是,添加不是这样做的,我不明白为什么.这是我的代码:
#include <iostream>
using namespace std;
int main (){
int a, b;
cout << "Please enter an integer: ";
cin >> a;
cout << "Please enter another integer: ";
cin >> b;
if (a*b %2== 0){
cout << "The product of " << a << " and " << b << " is " << (a*b)
<< " and is even." << endl;
}
else {
cout << "The product of " << a << " and " << b …Run Code Online (Sandbox Code Playgroud)