First of all:
use int main() instead of void main()
please use code tags, it makes your code easier to read as does indention
With that said:
you have a few typo's in your code:
void main()
{
Decode code;
Your class is called ' decoder ' not ' Decode', the line above to 'decoder code'
code.setdecodertype(choice);
There is no function 'setdecodertype'. Change this to 'setdecoderType'.
Please keep in mind that C++ is casesensitive and therefore: a!=A
Nick Evan
Not a Llama
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
This is a small program i have try to do but with errors... can anyone help me to solve up the error?
What error? We can't help it you don't tell us.
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
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.
rinoa04
Junior Poster in Training
84 posts since Sep 2006
Reputation Points: 52
Solved Threads: 4
usingnamespace std;
There should be a space between using and namespace
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.
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.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.
Nick Evan
Not a Llama
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
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.
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
Actually, 011 = 9. When you specify a numeric value with a leading 0, you are using an octal
Didn't know that, I thought (int)011 == (int)11. I've tested it in flamecly's program (by replacing 011 with 11 in the switch case) and it works as I'd expect: if user inputs 011, case 11 will be true.
How is that then? Perhaps 'cin' doesn't know how to handle octals?
Nick Evan
Not a Llama
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403