Where do you increment ctr after pushing?
JamesCherrill
Posting Genius
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
It starts at 0.
You push the next char into element [0]
Where should the next char go?
It doesn't matter exactly where you increment it, as long as its after pushing one char and before pushing the next.
JamesCherrill
Posting Genius
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
1. You need a big loop so that when case A has finished you go back up to the top and do it again.
2. That depends on whether you leave lttr alone between cases, or re-initialise it to a new array.
JamesCherrill
Posting Genius
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
Right now you've got a pretty linear command flow. User comes in at the top, and flows down through the code until they fall out the bottom. You could keep a similar linear flow, and simply loop around back to the case. I always wanted switch statements to have a "continue" to allow you to do this... no such luck, though. Maybe when I'm king... Anyway, you'd have to use a while loop to do that. That would still be linear, but now the line's got a loop in it.
If you wanted a little more structure in your code, you could make the input be a method, and again you'd loop on calling out to the method and returning the input. Handle the input in main (or in another method) and then go back out to the method. That would again use a while loop, but you'd be using a more modular approach.
Later on, you'll maybe think about getting into an OO approach - that's totally unnecessary here, but it might be good practice for you.
How would you change this to have a separate class handle the input and output? What if you wanted to switch between a console input (like you have here) and maybe a GUI? What would be the same about those two options, and how would you capture that?
jon.kiparsky
Posting Virtuoso
1,849 posts since Jun 2010
Reputation Points: 383
Solved Threads: 187