i'm making a program in c++ that gets a binary number and converts it to an integer. But of coarse i've hit a snag, I need a way to store a binary number that's any length, then run through the number to see if a 2 or something is there, if it is then to ask for a new number. Here is what I thought would work, but of coarse, it doesn't. (it's not completed, i just wanted to see if i could find out if they entered something other than a one or zero here):
int binToDec()
{
string binaryToConv = ("0");
bool reEnter = false;
cout << "Enter a binary number to convert: " << endl;
cin >> binaryToConv;
for(int counter = 0; ;counter += 1)
{
reEnter = false;
if((binaryToConv[counter] != 0) && (binaryToConv[counter] != 1))
{
reEnter = true;
break;
}
if(counter == binaryToConv.size())
{
break;
}
}
if(reEnter = true)
{
binToDec();
}
cout << "adsf";
}