So my project is to convert binary string into ascii or convert ascii into binary string. However, when the program is checking to see if the input binary string is valid or not, it either rejects good or bad inputs when I use && or accepts bad input when I use ||
void check_bin_number(std::string line)
{
bool check = false;
while (check != true)
{
for (int i = 0; i < line.length(); i++)
{
if (line.length() % 8 == 0 && (line.at(i) == '0' || line.at(i) == '1')) //Here is the problem.
{
bin_to_ascii(line);
check = true;
break;
}
else
{
std::cout << "ERROR." << std::endl;
get_user_input();
}
}
}
}
output when used "||"
Do you want to encrypt or decrypt a message? decrypt
Enter string: 12345678
Your input in ASCII is:
Your input in ASCII is:
output when used "&&"
Do you want to encrypt or decrypt a message? decrypt
Enter string: 12345678
ERROR.
Enter string: 09876543
ERROR.
Enter string: 011010100110010101101110
ERROR.
Enter string: