This program is almost complete, although it performs its function, that is, it converts base 10 number to base 2. However, I want it to be able to request from the user, to enter numbers for conversion until the user hit ESC key to exit the program.
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
usingnamespace std;
int main()
{
int num;
int bit1 = 0;
int bit2 = 1;
vector<int> iNum;
cout<< "\n\nEnter an integer value (Enter to exit): \n";
cin>> num;
do
{
if(num%2 == bit1)
iNum.push_back(bit1);
elseif (num%2 == bit2 || num == bit2 || num%2<bit2)
iNum.push_back(bit2);
else
iNum.push_back(bit2);
num = num/2;
}while (num>0);
int size = iNum.size();
cout<< "The computed binary value of the input integer " << num << " is: ";
int number = num;
for (int j=0; j<iNum.size(); ++j)
{
cout<< "\n" <<iNum[j];
}
cout << endl;
int k=iNum.size();
cout<< "The number is " << k << " bits \n\n" ;
cout<<"The binary value of the decimal value " << number << " is: ";
for(k=iNum.size(); k>0; k--)
{
cout<< iNum[k-1];
}
cout<< endl;
}