For a 2 input AND gate, you have 4 possible combination of inputs(0 to 3 in binary) . The output will only be a 1 if the two inputs are a 1, otherwise the output is a 0.
For a 2-4 bit decoder, you have an output for each combination of input. eg, If a=0 and b = 0 then D0= 0, or if a=0 and b=1 then D1=1 etc., just google the Truth Table for each chip. The 3-8 is the same with 3 inputs and 8 possible outputs...
Last edited by Colin Mac; Jan 10th, 2007 at 10:32 am.
cout << "Please enter the 3 binary code!(E.g. 001) "; cin >> choice;
code.setdecodertype(choice);
cout << "After decoding… The number is\n ";
code.showdecoder();
}
Thanks for helping in advance...
Last edited by WaltP; Jan 16th, 2007 at 4:24 am. Reason: Code Tags! When you enter your question, thos are instructions, not smudges, in the input box. Please read... And format your code so it can be read.
One of your coding mistake is as what nick stated. But there is also another mistake. Your coding is prompting the user for integer but in your switch case it is comparing integer with character. You should eliminate the single quote since it represent character. Then I think your coding should be working after you correct all the small mistakes. Hope it helps.
Last edited by Nick Evan; May 11th, 2010 at 9:04 am.
Thanks for your help for the previous errors...
Now i have rewrite the program but i still got some error and editing which need yours help.
Here is the code
There should be a space between using and namespace
Quote ...
First problem - For the 3 to 8 decoder, when 011 and 001 was keyed, it shows error instead of 3 and 1.
That's a problem with int's. 011 == 11 and is an invalid input. 010 will probably have the same problem. Try making the input to string and switch on that.
Or if you want to do it the ugly way: replace 011 with 11 and 010 with 10 in your switchcase.
Quote ...
Second problem - how can i edit the program so the users can choose to use either one of the 3 decoder? I have try alot of times but all got errors.
That's not that hard is it? Ask for a user input (1 for 3-8, 2 for etc.) Make a switch case on that and execute the right function.
Quote ...
Third problem - How can i do loop back if i key in a wrong value and i want to key in the value again after the error line has been shown?
you should work with returnvalues in your function. So if the input was valid return '0' and if it was invalid return '1'. Then call the function in a loop.
Last edited by Nick Evan; May 11th, 2010 at 9:05 am.
That's a problem with int's. 011 == 11 and is an invalid input. 010 will probably have the same problem. Try making the input to string and switch on that.
Actually, 011 = 9. When you specify a numeric value with a leading 0, you are using an [search]octal[/search] value. You can't specify binary the way you are trying to do it. Enter it as a string and convert the string into it's binary equivalent. And in the switch, just use it's decimal value.
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.