Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions