Question: Is there a way to solve this without using if-else statements I am having this error : Value of type 'const char [2]' is not

Is there a way to solve this without using if-else statements

I am having this error : Value of type 'const char [2]' is not implicitly convertible to 'int'

void hexToBin() {

cout << "please enter your hexcode" << endl;

string hexCode;

cin >> hexCode;

cout << "you have entered" << endl;

for (int i = 0; i < hexCode.length(); i++) {

cout << hexCode[i];

}

cout << endl;

string binCode[hexCode.length()];

for (int counter = 0; counter < hexCode.length(); counter++) {

switch (hexCode[0]) {

case "0":

binCode[counter] = "0000";

break;

case "1":

binCode[counter] = "0001";

break;

case "2":

binCode[counter] = "0010";

break;

case "3":

binCode[counter] = "0011";

break;

case "4":

binCode[counter] = "0100";

break;

case "5":

binCode[counter] = "0101";

break;

case "6":

binCode[counter] = "0110";

break;

case "7":

binCode[counter] = "0111";

break;

case "8":

binCode[counter] = "1000";

break;

case "9":

binCode[counter] = "1001";

break;

case "a":

binCode[counter] = "1010";

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!