Ok so I tryed to make a program in which i could enter any binary number and
transform it into a octal number (example. "111" would be "7"). The problem is
that when I am compiling it, it shows a error saying:
In function 'main'.
syntax error at the end of input
//It reefers to like 46, the one with the last brackets//
So my code is bellow and I hope you are able to understand it and solve my
problem, ty in advance.
I had to download and re-install Dev-C++ to compile this project and I have to
say that although you have the right idea, there are several issues that need
to be looked at.
Once you add the nessarry bracket you will find that out.
Add your closing bracket just before the final "for" loop.
I will help you further if you would like, but for now I will point you in the
right direction and let you see what else you can find out.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This compiles for me, although it does not work. I had to add the a to give
the a a reference point or it was comparing a string to a number with the
compilier would not allow.
May I also suggest that you avoid the use of the GOTO command. Although it is
very easy to use, it can cause you more headaches that it is worth.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Well I was looking at your problem and decided to see what I would do if I
were to be asked to write a program that did the same thing. First I would
convert to decimal first and then convert to oct. Just seems easier to me that
way. My binToDec function will do that for you and I have tested it. It can
use some work to handle longer binary numbers but works fine on teh smaller
ones.
int binToDec (int binNum)
{
int count = 0;
int returnVal = 0;
while (binNum>0)
{
if (binNum % 10) returnVal += pow(2,count);
binNum /= 10;
count++;
}
return returnVal;
}
Have not written the decToOct function yet but what I have written here may
help you solve your own problem. If I do not finish this tonight, you will not
hear from me for the rest of the week as I am leaving for holidays.
Curtis
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank very much to everyones help! I know I still got some problems to solve
that could come up, but this was mainly the main obstacle right now(now
solved), this program was only for made for a binary number of this type
"111"(atleast I wanted to so). now I am going to solve the problem if someone
just enters "1111" in which I particulary have to add another 2 zeros.
Well, ty very much again.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Not understanding why you need to add another 2 zeros if someone enters
"1111", do you need the number padded to 6 or eight digits? ex: 11 = 110000 or
1010 = 101000
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
if someone enters 1111, then I add 2 zeros for "001 111" so my program works
but I came upon a more complicated problem which I can't solve without being a
really good programer, so I am going to use my "Bin to Dek" & "Dek to Okt"
code which I made myself too.(Works without a problem)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I do not understand the need for the leading zeros. they will not affect the
actual value of the entered number. If you look through my code you will see
that they are unnessarry and adding them could why you are having issues. If
you were needing to add the numbers to the end then the values would change.
you should re-look at my code. It can handle 0001111 or 1111 as they will come
to the same number. Other than that, you would need to post your own functions
so I can try to determine where they are having issues.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
As for adding leading zeros, if you must do that then simply take the length
of your string % 3 and do a switch case on the remainder to determine how many
to add then string = "" & String
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ty for helping curtis8, but I already made 4 programs with avoiding that code
I started with-names are here:
Okt to Bin >> Okt to Dek>Dek to Bin
Okt to Hex >> Okt to Dek>Dek to Hex
Hex to Bin >> Hex to Dek>Dek to Bin
Hex to Okt >> Hex to Dek>Dek to Okt
Ty again for your help, everyone gave me some more knowledge about coding in
Dev-c++.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ok so I tryed to make a program in which i could enter any binary number and
transform it into a octal number (example. "111" would be "7"). The problem is
that when I am compiling it, it shows a error saying:
So my code is bellow and I hope you are able to understand it and solve my
problem, ty in advance.
for(i=0;i<=j;i++)
{
printf("%d",b_);
}
getch();
}
This is the correct last part, for some reason the _ won't show in the code
above.__
the "i" between the brackets wont show after <<(printf("%d",b);>>>
sorry very much for double replye to my own post
Well for starters you are missing a closing bracket "}"
so there is an unepected EOF
I would try to re-check all the brackets.
I had to download and re-install Dev-C++ to compile this project and I have to
say that although you have the right idea, there are several issues that need
to be looked at.
Once you add the nessarry bracket you will find that out.
Add your closing bracket just before the final "for" loop.
I will help you further if you would like, but for now I will point you in the
right direction and let you see what else you can find out.
include <stdio.h>
This compiles for me, although it does not work. I had to add the a to give
the a a reference point or it was comparing a string to a number with the
compilier would not allow.
May I also suggest that you avoid the use of the GOTO command. Although it is
very easy to use, it can cause you more headaches that it is worth.
Well I was looking at your problem and decided to see what I would do if I
were to be asked to write a program that did the same thing. First I would
convert to decimal first and then convert to oct. Just seems easier to me that
way. My binToDec function will do that for you and I have tested it. It can
use some work to handle longer binary numbers but works fine on teh smaller
ones.
Have not written the decToOct function yet but what I have written here may
help you solve your own problem. If I do not finish this tonight, you will not
hear from me for the rest of the week as I am leaving for holidays.
Curtis
Made a decToOct function. It too works fine (as far as I can tell). See if
there is anything that you can use to made your program work.
Curtis
int main()
Thank very much to everyones help! I know I still got some problems to solve
that could come up, but this was mainly the main obstacle right now(now
solved), this program was only for made for a binary number of this type
"111"(atleast I wanted to so). now I am going to solve the problem if someone
just enters "1111" in which I particulary have to add another 2 zeros.
Well, ty very much again.
dam... my english up there is verrryyyy bad!
Sorry for double replying again.
Not understanding why you need to add another 2 zeros if someone enters
"1111", do you need the number padded to 6 or eight digits? ex: 11 = 110000 or
1010 = 101000
if someone enters 1111, then I add 2 zeros for "001 111" so my program works
but I came upon a more complicated problem which I can't solve without being a
really good programer, so I am going to use my "Bin to Dek" & "Dek to Okt"
code which I made myself too.(Works without a problem)
I do not understand the need for the leading zeros. they will not affect the
actual value of the entered number. If you look through my code you will see
that they are unnessarry and adding them could why you are having issues. If
you were needing to add the numbers to the end then the values would change.
you should re-look at my code. It can handle 0001111 or 1111 as they will come
to the same number. Other than that, you would need to post your own functions
so I can try to determine where they are having issues.
As for adding leading zeros, if you must do that then simply take the length
of your string % 3 and do a switch case on the remainder to determine how many
to add then string = "" & String
Ty for helping curtis8, but I already made 4 programs with avoiding that code
I started with-names are here:
Okt to Bin >> Okt to Dek>Dek to Bin
Okt to Hex >> Okt to Dek>Dek to Hex
Hex to Bin >> Hex to Dek>Dek to Bin
Hex to Okt >> Hex to Dek>Dek to Okt
Ty again for your help, everyone gave me some more knowledge about coding in
Dev-c++.
Hi I use trial version of programming
software because I can't understand Which of
them are the best.
I learned something new again. Shall use this. Thanks!