Hi guys, can you re-write my program where it's mistaken ? I can't figure out how to convert my input string into binary :/ I will input 2 programs:the first is my current, and the other is an example from which I should figure out how to do it but I can't and it's driving me crazy.Please use only the following directories : "iostream,string,math".
I've been told that the second code is going to help me figure it out how to write my first one.I tried doing it like the second one - it got even worse.And I know it's bad I can't use <bitset> but .. I think the whole do-while function is the key thing in the second code but I can't figure out how to use it in the first one .. I've been trying for days now and my brain is literally melting..fck's sake
Yeah it's converting from decimal to binary.And from that I'm supposed to build my first code .. it's so fcked up dude .. so fcked up.. Please help if you have any ideas how can this happen.
a decimal number to binary number.Well actually if you want don't use the second coding at all.Just make the first one work, I don't care how just make it work please .. and as I said no <bitset>, sadly.I'm going to take a shower, if you're willing to re-write it so it can work - take your time.(please do it since I'm desperate as fck)
void DecToBin(int x)
{
int a[100];
int i=0;
do
{
a[i]=x%2;
x=x/2;
i++;
}
while(x!=0);
for(int j=i-1;j>=0;j--)
cout<<a[j];
cout<<" ";
}
int main()
{
cout<<"Enter the string to convert to binary:: ";
char i[50];
gets(i);
int j=strlen(i);
for(int k=0;k<j;k++)//the loop will end only when all the stuff is converted to binary
{
int num=i[k];//converting char to its numerical ascii value
DecToBin(num);//just calling the function in the loop
}
return 0;
}
Everything is perfect .. but .. can you change a bit the int main ? I mean there is coding in there that I haven't even studied and it would be a bit suspicious if I hand in something I haven't studied ..
1 2 3 4 5 6 7
char i[50];
gets(i);
int j=strlen(i);
for(int k=0;k<j;k++)
{
int num=i[k];
DecToBin(num);
I'm going to follow your lead then .. heahea.Thank you a lot dude.Since you're the only guy that helped me in a way I can hand it in can you help me with further programs ? I'm not saying something like : help me with every program from now on.. I'm just asking if you can help me with programs I literally have no idea how to deal with.
btw figured out how to change it so it can look authentic as if I have written it (all of it)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
int main()
{
cout<<"Enter the array which you want to convert into binary : "<<endl;
char a[50];
cin.getline(a,50);
cout<<"The array which you wrote converted into binary looks like : "<<endl;
for(int k=0;k<strlen(a);k++)
{
int n=a[k];
DecToBin(n);
}
cout<<endl;
system("pause");
return 0;
}