I am calculating a full expression regardless of spaces. So I have a program that accepts a string ex: "56 + 67", and passes it by reference to a void function that first removes the spaces and sets it to correctly to "56+67",
it then returns to main and passes it to the void process function to correctly process it according to the specifications laid out in the lab details.
if the string is equal to q or Q it will return and exit, if not it will run another check and then a for look to check for any characters in the string that are not digits or +-*%/ operators. If it is not a digit, it checks if it a operator and if it isn't it couts and returns back to main.
1 2 3 4 5 6 7 8 9 10 11 12 13
elseif(userInput != "q" || userInput != "Q"){
for(int i=0; i<userInput.size(); i++){
if(!isdigit(userInput[i])){
if(userInput[i] != '+' || userInput[i] != '%' || userInput[i] != '-' || userInput[i] != '*' || userInput[i] != '/'){
cout << "Input cannot contain any characters that are neither digits,";
cout << " an operator, or the quit command\n";
return;
}
elsecontinue;
}
}
for some reason I can't figure out it'll still cout the error message when the expression is "56+67"?? Any help please.
ahh I see! I missed that. Just took it out and replaced it with
1 2 3 4 5 6 7
for(int i=0; i<userInput.size(); i++){
if(isalpha(userInput[i])){
cout << "Input cannot contain any characters that are neither digits,";
cout << " an operator, or the quit command\n";
return;
}
}