Computer Science Canada Decimal to Binary. First turing project ever. |
Author: | Voltage128 [ Wed Nov 29, 2006 9:30 pm ] | ||
Post subject: | Decimal to Binary. First turing project ever. | ||
Something I threw together in about 5 min today for my comp teacher, he wanted us to use "-1" to end the program instead of just typing "stop" or "end" because he says "-1" is easier to do. Then he pinged me marks later for it. What do you guys think?
|
Author: | Clayton [ Wed Nov 29, 2006 9:57 pm ] |
Post subject: | |
good job, now make that a function that error traps for improper input. as for inputting -1 as an exit condition, thats pretty foolish, using a simple "y/n" is probably the better idea. |
Author: | Voltage128 [ Wed Nov 29, 2006 10:28 pm ] | ||
Post subject: | |||
alright, i think that is better for the exiting the program. If i need to correct it again please let me kno, im learning. Also how would i go about making a function that error traps for improper input?
|
Author: | frank26080115 [ Fri Dec 01, 2006 4:54 pm ] | ||||
Post subject: | |||||
thats pretty kickass, i had to make one for class too
and i had to do a binary to decimal
|
Author: | Voltage128 [ Fri Dec 01, 2006 5:08 pm ] |
Post subject: | |
yea, my teacher actually takes marks off mine if I did the error check thing. Since in the book it doesnt ask for a error proof he says its un-needed and he takes marks off for not following the instructions. Which is stupid because all i learn are the basics of the program and i want to learn more. So explain to me how you did that error check please? |
Author: | uberwalla [ Fri Dec 01, 2006 6:43 pm ] |
Post subject: | |
ok a little off the wack but how did u guys know the formula for binary to decimal and back etc.? is that the ACTUAL formula or made up? cuz i see u both got same one |
Author: | frank26080115 [ Fri Dec 01, 2006 7:27 pm ] |
Post subject: | |
strintok means if this string is able to be converted into a number, then its ok, if the string contains letters then it is not ok and it will ask for the input again oh and i dont know anything about "mod" so i calculated manually binary 0001 is 2 ^ 1-1 = 1 binary 0010 is 2 ^ 2-1 = 2 binary 0011 is 2 ^ 2-1 + 2 ^ 1-1 = 3 binary 0100 is 2 ^ 3-1 = 4 so if the decimal number is 6 6 - (2 ^ 3 - 1) = 2 2 - (2 ^ 2 - 1) = 0 0110 reverse the process to get binary to decimal, which is a lot easier |
Author: | Voltage128 [ Fri Dec 01, 2006 8:02 pm ] |
Post subject: | |
mod just gets the remainder of a number when u divide it. so when u are doing a decimal to binary conversion lets say 5 you would go 5/2 = which gives you 2 and a remainder of 1 then u take the 2 on top divide that by 2 and u get 1 and a remainder of 0 therefore 5=101 you take the last 1 and the 2 remainders to get the binary number. Its just one way of figuring out the conversion. Mod just calculates the remainder. |
Author: | jamonathin [ Sat Dec 02, 2006 8:56 pm ] |
Post subject: | |
Freakman wrote: as for inputting -1 as an exit condition, thats pretty foolish, using a simple "y/n" is probably the better idea.
How so Freakman? -1 in this case is better than y/n. Y/N implies that he would either have to make a completely different get statement OR make his input-variable string, then convert the string after the input -> causing more work. So it's either, annoyance to the user, or more work for the programmer. As an end result, -1 FTW. (ps. my profs use -1) |
Author: | Voltage128 [ Sat Dec 02, 2006 9:16 pm ] |
Post subject: | |
-1 was a lot easier to do I agree. But it isnt that much work to put a yes/no as an exit condition. For this case however, i do like the -1 as an exit condition better. I did realize that it is really annoying to have they yes/no in the program. Everytime it asks if you would like to continue. |
Author: | Silent Avenger [ Sat Dec 02, 2006 9:24 pm ] |
Post subject: | |
-1 is easier but you also have to think about the user. To an average user it would be a lot better for them to have a Y/N option. Although you program is most likely not going to be used by the average Joe on the computer anyways. |
Author: | Voltage128 [ Sat Dec 02, 2006 9:56 pm ] |
Post subject: | |
Yes it decimal to binary isnt a common thing most people use everyday. So then you are agreeing that the -1 exit condistion is better suited for this program? |
Author: | jamonathin [ Sat Dec 02, 2006 10:05 pm ] |
Post subject: | |
for a game, or a full scale program (with many subprogs), yes, y/n is lovely, however, for simple progs that deal with people going "ok whats this, now whats this, and this" wanting fast answers, they wont want a convo with the program. But anyways, i think we're getting a little off topic. Gj btw. |
Author: | Silent Avenger [ Sat Dec 02, 2006 10:35 pm ] |
Post subject: | |
Voltage128 wrote: Yes it decimal to binary isnt a common thing most people use everyday. So then you are agreeing that the -1 exit condistion is better suited for this program? Yes I am agreeing that the -1 exit condition is better suited for this program in your situation than the Y/N. |