I am trying to make a program that will convert a decimal number to its binary equivilant. It will output the first number but I am having trouble figuring out how to use the previously found quotient to find a new quotient. I tried using loops to do this and they are always infinite.
Here is the code I have written so far
Code:#include <iostream> using namespace std; void convert (int); int main () { int num; cout <<"Please enter a number to convert" <<endl; cin>>num; convert (num); return 0; } void convert (int num) { if (num>0) { double quotient,remainder; quotient=num/2; remainder=num%2; if (quotient==0) cout <<" "; else { if (remainder==0) cout<<"0"; else if (remainder==1) cout<<"1"; } } else cout<< " "; }