hello, I am working on a program that takes numbers 0-255 and converts them to binary and hexadecimal and bcd. I believe my algorithms and remove function are correct but when I call the function in int main() I get an error saying the program is not responding. Any help would be appreciated.
Code:
#include <iostream>
using namespace std;
class converter
{
private:
int bin[12];
int remainder;
int newValue;
int k;
public:
converter();
void binary(int);
void hex(int);
void bcd();
int remove();
};
converter::converter()
{
int remainder = 0;
int newValue = 0;
int k = 0;
}
void converter::binary(int num)//converts to binary from decimal
{
newValue = num;
while(newValue >= 1)
{
remainder = newValue%2;
if (remainder == 0) //sends the value into the correct if statement.
{
bin[k] = 0;
k++;
}
else
{
bin[k]= 1;
k++;
}
newValue = newValue/2;
}
}
void converter::hex(int num)
{
remainder = num % 16;
while(newValue >= 1 )
{
remainder = newValue%16;
bin[k] = remainder;//used to add the remainder into the array
k++;
newValue = newValue/16;
}
for(int z = k; z < 12; z++)//fills up the array to follow the format
{bin[k] = 0;}
}
void converter::bcd()
{
}
int converter::remove()//print out the values and remove the vaules reading the array for the new values.
{
int temp = bin[k-1];
k--;//brings k back to 0 allowing for more info to be added to the array
if(temp <= 9)//converts to the appropriate letter for hexadecimal.
{
return temp;
}
else if(temp = 10)
{
temp = 'A';
return temp;
}
else if (temp = 11)
{
temp = 'B';
return temp;
}
else if (temp = 12)
{
temp = 'C';
return temp;
}
else if (temp = 13)
{
temp = 'D';
return temp;
}
else if (temp = 14)
{
temp = 'E';
return temp;
}
else
{
temp = 'F';
return temp;
}
}
int main()
{
int i = 10;
converter a,b,c;
cout << i <<endl;
a.binary(i);//function call
cout << "do we make it past binary";
for(int o = 1; o>= 0; o--)
{
cout<<a.remove();//attempt to print off the array values
}
cin.get();
return 0;
}