#include <iostream>
#include <conio.h>
usingnamespace std;
int main()
{
int x, y, remainder;
cout << "Enter first integer: ";
cin >> x;
cout << "Enter second integer: ";
cin >> y;
cout << endl;
// x % y
if (y != 0) {
if (x % y == 0)
cout << "x: " << x << " is a multiple of " << "y: " << y << endl;
else
cout << "x: " << x << " is not a multiple of " << "y: " << y << endl;
} else
cout << "Can not divided by zero, operation faild.";
getch();
return 0;
}
I think your original code is preferable. 4 is not a multiple of 0, so if I enter 4 and 0, it should just say that 4 isn't a multiple of 0.
Put another way, why would I, the user of the program, care if the program had to divide by zero? I'm not interested in division, I'm interested in multiplication. The fact that you had to divide to determine the answer is your problem, not mine. It's an internal error that I shouldn't have to deal with.