This is my code for the problem.
[admin: hiding the code]
It works properly but it looks hideous. I am looking for some nice inputs to re-write it in a more elegant way.
CS50 Stack Exchange is a question and answer site for students of Harvard University's CS50. It only takes a minute to sign up.Sign up to join this community
Edit to rephrase, I hope this one is ok with the admin.
Operate on a copy of the number (so that you can use the number later for other things). Use a loop, can be a pretty simple while loop, and process only the last digit (
% 10), or the last two digits within the loop. After that, divide the (copy of the) number by 10 if you processed one digit, or 100 if you processed two. Processing two at once has the advantage that you don't have to track whether a digit requires doubling or not.
You can do a similar loop to get the first two digits.
Those can be performed before the whole switch statement. I'd do some if-else chain instead, but why not.