I'm only 9 chapters into the dummies guide to C++ and I am completely new to the programming world. I'm learning on my own and I'm seeking help understanding what I am doing wrong. I have spent time re-reading the chapters I've covered so far and have gone further to write my own programs using the course material that get's covered and have encountered a problem that I would very much like help with. Under the if(nState == 4) I use a switch statement to allow for the user to input the abbreviation of any of the 50 states. It follows with defined case commands for all the variable which work. Though, the nTaxCode will not accept the value as defined nTaxCode = 1; to carry that value after the break to complete the program. Am, I a, not able to carry the value with the switch and case statements beyond the case statements, or am I writing the case statement for what nTaxCode will be??
See now, that's the problem the compiler does not report any errors. Yet when I run the program and activate the nState switch and enter the start abbreviation I receive a Run- Time Check Failure#3 - T. I wrote a switch command earlier in the code without issue. Though I wasn't trying to apply a value to an int.
When I debug the program in visual studios it tells me "The variable 'nTaxCode' is being used without being initialized." Which only informs me of my initial question. Why when I use switch and case does it not accept the value entered for nTaxCode after the break;?
> the compiler does not report any errors no, they are warnings.
No, they are warnings.
That's why you need to enable the warnings when compiling.
> does it not accept the value entered for nTaxCode
it never sets any value because all the cases fail. 'al' is not a character. And I wonder about nState
Thank you but my warnings are set to show and none show. No errors, no warnings, no issues with the build until it runs. ak and al are just abbreviations of states as the program will eventually calculate taxes for the state entered. nState is written "char nState;" which was added in the earlier set of the code which does not currently show. When a user selects option 4 it prompts them to enter their state abbreviation. The case as I understand is then written for every instance a user can input the abbreviation. Followed then by the cammand if they do which I'm attempting to then give nTaxCode a value with "nTaxCode = 1" or 2, or 3, or so on. Though nTaxCode does not initialize the requested value for the continuation of the program after the break;.
Sure nState is of type char, but non of the cases are of type char. char is a single character, like a or b or c. Not 2 characters like al, AL and Al. So non of the cases will ever be true.
Well that makes sense. Thank you very much. I will have to review the book again, though I do not recall it stating such as it should. Though, again it may go into more detail on the subject in later chapters. I've been running laps trying to rewrite my code to make it function. Seems that this part cannot function at all and will need to be rewritten. Still though, thank you very much.