My function's being dumb.
Hi.
I'm trying to write a C++ program for class that'll take two numbers and see if one is a multiple of the other. I'm doing this with a function and by repeatedly subtracting the bigger number by the smaller one until the value left over is "0" or lower.
However, I am running into quite a stupid problem. I can get it to display the left over number and it'll either output "0" or lower letting me know that the code worked.
As soon as I put in an "if" statement and a "cout << " to display either "True" or "False", it just... resets the number back to '0'? wtf?
This is what I have so far:
Code:
//Page 274
//Question 6.20
#include <iostream>
using namespace std;
int multiple(int a, int b){
int c;
if(b>a){
c = b;
while(c>0){
c-=a;
}
}else if(b<a){
c = a;
while(c>0){
c-=b;
}
}
return (c);
}
int main(){
int numone, numtwo;
int ismultiple;
cout << "Enter a number: ";
cin >> numone;
cout << "Enter another number: ";
cin >> numtwo;
ismultiple = multiple(numone, numtwo);
if(ismultiple=0)cout << "True.\n";
cout << ismultiple << endl;
return 0;
}
Now comment out that "if(ismultiple=0)cout << "True.\n";" line and the code works. It displays the right number.
Am I doing something wrong?