Please forgive the following precise, pedantic, and tiresome rant; but I think it will help to dispel some confusion. Your problem statement ought to be something more like this...
Write a program that does the following:
- Accept a user-entered string that contains a nonnegative decimal number.
- Validate the string (print an error if it contains anything other than the digits 0-9 or it has a value greater than can be held in whichever integral type you choose to use).
- Convert the string into a number.
- Print the value of the number as a string of binary digits.
- Print the value of the number as a string of octal digits.
- Print the value of the number as a string of hexadecimal digits.
You'll have to add the part about the user specifying the output format. Perhaps you are required to handle negative values.
You convert from string to number and then from number to string; but the integral number itself doesn't change once you've got it. Other posters have gotten quite confused -- thinking that they need to alter the way C stores integral values.
C++ has automagical ways to do these string conversions. It sounds like your assignment requires you to deliberately avoid doing it the easy way for the output strings. Are you allowed to take the easy way for converting the input string into the number?