I am trying to determine if a number is a multiple of another number. I have the user enter a number, then a second number to check if the second is a multiple of the first number entered.
I decided to divide the two numbers and check to see if the multiple number is whole or not. I round up the answer (if it's a decimal it isn't a multiple), and check to see if it is more than the second number entered or equal to it, then do output based on the result.
#include <iostream>
#include <math.h>
usingnamespace std;
double number;
double multiple;
double num;
double num2;
bool factor;
bool multiples (bool);
int main()
{
cout << "Enter a number you want to find a multiple for." << endl;
cin >> number;
cout << "Enter another number to test if it is a mulitple of the first number." << endl;
cin >> multiple;
multiples(factor);
if (factor = true)
cout << multiple << " is a multiple of " << number << "." << endl;
if (factor = false)
cout << multiple << " is not a multiple of " << number << "." << endl;
return 0;
}
bool multiples (bool a)
{
num = number/multiple;
num2 = ceil(num);
if (num < num2)
factor = false;
if (num = num2)
factor = true;
return factor;
}
No matter what it wants to execute
1 2
if (factor = true)
cout << multiple << " is a multiple " << number << "." << endl;
I debugged by entering 5 and 2, and factor will be false (since 5/2 = 2.5. 2.5 rounds up to 3, so 3 > 2), but as soon as it gets to that line it will change to true regardless.
It won't let me use %. It says "expression must have integral or enum type"
As for the other 2 questions, what do you mean? It won't work without returning a value as far as I can tell. Am I doing something redundant?
if( multiples(number, multiple) )
cout << multiple << " is a multiple of " << number << "." << endl;
else
cout << multiple << " is not a multiple of " << number << "." << endl;