올바르게 작동하는 다음 코드가 있습니다. 내가 다른 문 아무것도 추가 그러나 후 항상 이전이 제대로 입력이 무엇인지에 따라 평가하는 모든 다른C++ 문자열 조작 - stament가있는 경우
wgetstr(inputWin, ch); //get line and store in ch variable
str = ch; //make input from char* to string
if(str=="m" || str=="M"){
showFeedback("Data Memory Updated");
}
if(str=="p" || str=="P"){
showFeedback("Program Memory Updated");
}
if(str=="g" || str=="G"){
showFeedback("Accumulator, Program Counter, Zero Result Updated");
}
if(str=="e" || str=="E"){
showFeedback("Editing Mode Enabled");
}
if(str=="c" || str=="C"){
showFeedback("Program Copied Into Program Memory");
}
if(str=="r" || str=="R"){
showFeedback("Executing Program");
}
if(str=="x" || str=="X"){
showFeedback("Program Exited");
}
로 평가됩니다. ie "m"을 입력하면 showeFeedback ("Data Memory Updated")이 계속 호출되지만, 다음 else 문을 추가하면 입력 한 내용에 관계없이 항상 잘못된 명령 입력이 발생합니다.
else{
showFeedback("Invalid Command Entered");
}
이것은 사용자의 문제와 관련이 없지만 str을 대문자 (또는 소문자)로 변환하여 조건에 해당 문자를 모두 포함하지 않도록 할 수 있습니다. –