heyy all :)) So im working on a new piece of code here..take into consideration that I love while loops and that's what I really want to use!

so here is how the program would go
read: #
then
read: base
print: decimal representation

thanksss :))

show us what you got

I have no ideaa where to start im so lostttt

Err...

read: # <-- a number?
then
read: base <-- you mean base number, such as 2 (binary), 8 (octa), etc.???
print: decimal representation <-- you mean base 10 number???

If so, you should start with write down a step-by-step of what you would do when you want to create a program. You already got...

/*
  +--------------+
  |  read input  |
  +--------------+
         |
         V
  +--------------+
  |  read base   |
  +--------------+
         |
         V
+------------------+
|  display decimal |
+------------------+
*/

Now what you need is to expand each of the rectangle to smaller tasks. The loop can come later once you can get it working.

Err...

read: # <-- a number?
then
read: base <-- you mean base number, such as 2 (binary), 8 (octa), etc.???
print: decimal representation <-- you mean base 10 number???

If so, you should start with write down a step-by-step of what you would do when you want to create a program. You already got...

/*
  +--------------+
  |  read input  |
  +--------------+
         |
         V
  +--------------+
  |  read base   |
  +--------------+
         |
         V
+------------------+
|  display decimal |
+------------------+
*/

Now what you need is to expand each of the rectangle to smaller tasks. The loop can come later once you can get it working.

yes..he specified binary..I have never seen stuff like this before thats why I am so lost :((

Im lost on coding the output..i know how to read the number and the base...just have no idea on how the binary..help!!

I was thinking using

switch case '1':

res = ((x-48)*4) + (y-48)*2) + (z-48)*1))
something like that for each case

Well, how about you think of it in each case. There should be 4 cases in this case...

case #1 - enter base 2 number, you can easily convert a binary (with 0 and 1) by iterating through the number and add the total sum of 2^(n-1) where n is the number of digit entered.

case #2 - enter base 8 number, you can do the same thing as in base 2

case #3 - enter base 10 number, you just simply display it.

case #4 - enter base 16 number, you also do the same thing as in base 2 & 8.

What you really need to keep in the loop are...
1)The input number must be 0, 1, 2, .., 9, A~F. Other input will be reject and need to be reenter.
2)After you accept a number, you must verify that the base type enter matches the number type. For example, a base 2 must consist of only 0 and 1. If it doesn't match, you could either reject and ask for a new input number or reject and ask for a new base number.

You need to solve this 2 loop problem first. Once you get correct input values, you compute and display result. After that you may add another loop for user to either enter again or quit. That's all...

PS: Use a loop to go through a number string when compute. Why do you need hard coded when you can actually read each character from the input number string using a loop?

Edited 5 Years Ago by Taywin: n/a

This article has been dead for over six months. Start a new discussion instead.