CheckIfUserInputEvaluationIsATarget Flashcards
(4 cards)
How does the program evaluate the user expression, from checking whether it is a valid expression and how it handles incorrect expressions?
Converts the user’s expression in RPN to an integer or returns -1 if the result was non-integer.
int UserInputEvaluation=EvaluateRPN(UserInputInRPN);
bool UserInputEvaluationIsATarget = false;
returns false if the users input doesn’t evaluate to a target.
How does the program remove a target if the users expression matches a target?
Loops through all targets. If the result matches a target, awards +2 to Score, sets that target to -1 (marking it cleared), and sets the boolean to true.
for (int Count = 0; Count < Targets.Count; Count++)
{
if (Targets[Count] == UserInputEvaluation)
{
Score += 2;
Targets[Count] = -1; // mark target as cleared.
UserInputEvaluationIsATarget = true;
Set a boolean so we know we hit at least one target.
}
What is returned when the user successfully hits a target at the end of this function?
Tells the caller whether the user successfully hit a target.Set a boolean so we know we hit at least one target.Return whether at least one match was found.
return UserInputEvaluationIsATarget;
What is the main function of this program?
decides if a user’s expression has “cleared” any targets. Called every turn from PlayGame.