I am trying to figure out how to convert a number to binary. I am running into the problem where it either goes into an infinite loop or it only does one conversion. Any help just trying to figure out how to properly do the loop would be amazing, thanks.
#include <iostream>
usingnamespace std;
int main()
{
int a = 0;
cout << "Input number to convert to binary here: ";
cin >> a;
do
{
cout << a % 2;
a = a/2;
} while (a != 0);
return 0;
}
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{
int store[100] = { 0 };
int index = 0;
int a = 0;
cout << "Input number to convert to binary here: ";
cin >> a;
do
{
store[index] = a % 2;
cout << store[index];
a = a / 2;
index++;
} while (a != 0);
cout << endl;
for (int i = 0; i < index; i++)
cout << store[index - i - 1];
cout << endl;
return 0;
}