### Basic Number Theory Test

Hello. I am trying to write a program for class where the user inputs two numbers (non-negative) and determines whether their product is within 2 of a multiple of ten. I am now trying to figure out how to determine whether the product is within a multiple of ten. I have figured that I need to test whether x * y equals a certain number (z), but I am not sure what qualities I should assign to z. I have tried using something like... if (z%10 == 0) ...then I would use that value of z to determine if the product is a multiple of 10. I would really appreciate some help with this problem. Thanks.

 ``12345678910111213`` `````` #include using namespace std; int main() { int x, y, z; cout << "Enter the first number.\n"; cin >> x; cout << "Enter the second number.\n"; // I am not sure what to put on the new line or if I am even taking the right path on this at all. z = if (x * y == z) return 0; }``````
What do you mean by "within 2 of a multiple of ten"? As in, if

xy = 10k ± 2

It will help you to remember that while `%` is called the "modulo" operator, but it would be more correct to call it the remainder operator.

That's a major hint right there.

One other thing: in C and C++, `%` is not defined over negative values. Make sure that you compute |xy|.

Good luck!
Topic archived. No new replies allowed.