Write a function multiple that determines for a pair of integers whether the second integer is a multiple of the first. The function should take two integer arguments and return true if the second is a multiple of the first, false otherwise. Use this function in a program that inputs a series of pairs of integers.
. Example: If input is 256 and 8, output will be 256 is a multiple of 8
If input is 13 and 111, output will be 111 is not, a multiple of 13.
I don't understand the question can you help me pleas??
I would use a bool function to assist you in this. Or you can just use an if else statement.
A mod (%) could also be of use. So if there is a remainder your value is not a multiple of valueA.
It appears to be a problem mainly about the math. I hope this helps get you started.
to check if the first number is a multiple of the second number, divide the first number to the second if there is a remainder. if there is a remainder, then it is not a multiple of the second number.
example:
first number = 256
second number = 8
256/8 == 32.0 ///see? no remainder
like wat murphyslaws said, use mod (%) since it gets the modulus.
#include <iostream>
bool multiple(int x , int y)
{
int remainder;
remainder = x % y;
if (remainder == 0)
returntrue;
elsereturnfalse;
}
int main(){
int x;
int y;
std::cout << "Enter the 1st value: ";
std:: cin >> x;
std::cout << "Enter the 2nd value: ";
std::cin >> y;
if (multiple(x,y) == true)
std::cout << y << " is multiple of " << x;
else
std::cout << y << " is not a multiple of" << x;
return 0;
}