ok so for some reason its telling me my "else" has no matching "if" in line 51, i have to make it so the binary output is spaced which im pretty sure i did and has to have a separate output if the character length is more than 8
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
void HextoBin (char[]);
void Binary (char[]);
void CheckHex (char[]);
string binary;
void main()
{
char hex[8];
int hexadecimal;
HextoBin (hex);
Binary (hex);
cin>> hexadecimal;
}
void HextoBin( char hex[])
{
string Hexa;
int hexval;
cout<< "Enter hexadecimal value: ";
cin>> Hexa;
hexval = Hexa.length();
do
{
if (hexval == 8)
{
for(int h = 0; h <= 8; h++)
hex[h] = Hexa[h];
}
}
}
void CheckHex(char hex[])
{
for (int h = 0; h < 8; h++)
if (hex[h]=='0'||hex[h]=='1'||hex[h]=='2'||hex[h]=='3'
||hex[h]=='4'||hex[h]=='5'||hex[h]=='6'
||hex[h]=='7'||hex[h]=='8'||hex[h]=='9'
||hex[h]=='a'||hex[h]=='b'||hex[h]=='c'
||hex[h]=='d'||hex[h]=='e'||hex[h]=='f'
||hex[h]=='A'||hex[h]=='B'||hex[h]=='C'
||hex[h]=='D'||hex[h]=='E'||hex[h]=='F')
else
cout<< "Error: incorrect character or length" <<endl;
}
void Binary(char hex[])
{
for (int i = 0; i < 8; i++)
switch (hex[i])
{
case '0':
" 0000";
break;
case '1':
" 0001";
break;
case '2':
" 0010";
break;
case '3':
" 0011";
break;
case '4':
" 0100";
break;
case '5':
" 0101";
break;
case '6':
" 0110";
break;
case '7':
" 0111";
break;
case '8':
" 1000";
break;
case '9':
" 1001";
break;
case 'a':
" 1010";
break;
case 'b':
" 1011";
break;
case 'c':
" 1100";
break;
case 'd':
" 1100";
break;
case 'e':
" 1110";
break;
case 'f':
" 1111";
break;
case 'A':
" 1010";
break;
case 'B':
" 1011";
break;
case 'C':
" 1100";
break;
case 'D':
" 1100";
break;
case 'E':
" 1110";
break;
case 'F':
" 1111";
break;
default:
cout<< "Enter hexadecimal value " ;
}
cout<< "Your hexadecimal value in binary is: " << binary <<endl;
}