I'm new (to both the forum and the language), and I'm at an impasse with an assignment. I wonder if someone would point me in the right direction. I've checked around the site (including the control tutorial and a search of the beginner's forum for "switch") and net and haven't found a completely satisfactory solution. This is my first C++ assignment ever. (Mercy, please!)
I'm required to use Visual Studio 2005, and my program is compiling with no errors. I've bolded the areas in question (to the best of my ability.)
I have a switch statement inside of a do-while loop. (I don't think the do-while loop is working properly either, but one problem at a time.) When I select case x, the program is supposed to display the totals for each category of expense claims. However, when I select x, I get my default case instead. I wonder if the program is implicitly casting x as an int for me or if I need to explicitly cast it somehow to make it work correctly. At one point, the compiler told me that x needs to be a constant, which is why I tried declaring it as such. My brain is fried at this point from staring at the code, and I've run out of ideas to tinker with. Can I use both int's and char's in one switch statement? If not, any thoughts on how to proceed? I'm required to use x as the display totals case. Am I at least on the right track?
I forgot to add that when I select x, I get the default statement, but the console window flickers, like it's in an infinite loop. Not sure if that matters.
Your variable 'choice' is an int, and thus can only hold an integral value. The letter 'x' is not an integral value, so that's inappropriate for this situation.
Since the user is inputting a character, you'll want to use char for input. You'll then want to compare it with the characters '0', '1', 'x', etc. Not the numbers 0, 1, etc
Thank you for posting in an intelligent, comprehendable, and well formatted manner. I can't tell you how many people come to these boards and post ambiguous questions and slap their code in without any explanation/formatting/etc.
Seeing posts like this from newcomers is a nice breath of fresh air. We need newbies to use this post as an example of how to ask a question the right way.
That did it! Many thanks to you, Disch! It's so easy to lose perspective and have tunnel-vision sometimes. Now off to fix everything else...
Thank you for posting in an intelligent, comprehendable, and well formatted manner. I can't tell you how many people come to these boards and post ambiguous questions and slap their code in without any explanation/formatting/etc.
Seeing posts like this from newcomers is a nice breath of fresh air. We need newbies to use this post as an example of how to ask a question the right way.
I'm not sure what to say, except you're welcome and thank you. Communication: It's what's for dinner. :~)