So my code requires me to use exception handling. I wrote it out, but for some r
ID: 3769698 • Letter: S
Question
So my code requires me to use exception handling. I wrote it out, but for some reason it keeps giving me the error member reference base type 'char' is not a structure or union. Could anybody help me debug the following section of my code?
char get_user_command( )
// Library facilities used: iostream
{
char response;
cout << "Enter choice: ";
cin >> response; // Input of characters skips blanks and newline character
if(response != 'C' && response != 'P' && response != 'S' &&
response != 'A' && response != 'R' && response != 'Q')
{
bool isNum = true;
for(int k = response; k != response; ++k)
isNum &&= isdigit(*k);
if(!isNum)
throw "User has entered an Invalid Option";
else throw "User entered a number";
}
return command;
}
Explanation / Answer
There are numerous mistakes in the program. It would have been better had you posted the entire code.
Mistakes::
1) k is not a pointer then why did you do *k ?
2) for(int k = response; k != response; ++k)
isNum &&= isdigit(*k);
doesnt make any sense. If k is a pointer then it should be a char pointer because it is pointing at response which is char . Further more what are you trying to achieve by the condition k!=response, it doesnt make any sense
3) what is the data type of "command"?
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.