Updating a stored comparison

A controller stores a cumulative item count. Before the first pass shown, count is 9. The output on pin 7 should be HIGH exactly when the count at the end of a pass is at least 10. Pin 7 is configured as OUTPUT.


The following fragment runs once per pass. newItem is a Boolean flag supplied by other code that identifies a newly detected item for that pass; resetRequested is another supplied flag. Both flags already have their stated values before this fragment begins.


C++
bool full = (count >= 10);
if (newItem && !full) {
  count++;
}
if (resetRequested) {
  count = 0;
}
digitalWrite(7, full ? HIGH : LOW);


On the first pass, newItem is true and resetRequested is false. On the second pass, both flags are false. Which statement correctly identifies the two values written by the original code and repairs the output for changes caused by either counting or resetting?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Arduino Programming Questions: