I don't have any syntax errors, but when I enter a number between 0 and 65536 I expect the function to return a value of 0 for error, but it keeps returning 1. I am convinced that I have a tiny retarded error that I cannot find.
The code asks for a user to input a number then returns one of 3 error codes, if error 0 then the number the user entered is also returned. I know the structure may not be the most efficient means of solving the problem, but I am working within the confines of a very strict assignment.
Mixing cin and cin.get is, to my knowledge, not good, because cin actually leaves the newline character in the stream, so your cin.get reads the stream, which is '\n'. You can flush the stream with an endl or a cin.ignore(), then you should be able to continue using both.
Sorry, I am very new to C++. Are you sure cin.get() will work that way? When I tried your code, it just set Ch to int value of 10 (which is a newline).
If you mean to take the Answer variable as a string instead of a char, I agree. But the int should stay an int; taking a number as a string unnecessarily complicates things.
iLiberate, then all your cin statements can be getline, which discards the null operator when it's done reading.
You need a to have a comparison against 65535, so if (input >65535) cout an error message. That should take care of your 'illegal' numbers.
Use the getline function as noted above, which skips leading whitespace (1). Then, as your input is now a string, you can access it like array elements. So, take in a number, then do something like:
Your assignment says to get the input one value at a time, so you may have to resort back to using a char instead of a string, but then you can still use the cin.get function:
Okay, don't do strings, do char instead like you originally had. And the get function is just in the istream class. You have indeed used them in class, since your original program has cin.get in it (from the istream class). Click on the link and read the page. An example is at the bottom.
The real problem here is that you aren't converting the characters to an integer correctly. At line 40, Ch is an ASCII character representing a digit between 0 and 9. It's value is between 48 and 57 (the ASCII values for '0'-'9'. To convert from the ASCII value of a digit to it's numeric value, simply subtract '0': X = (X*10) + (Ch - '0');