Need help with bottle counting machine

Hi!
Me and some friends are making a bottle counting machine, and I need some help
I'm using an ultrasonic sensor to recognize the bottles, and that part works well.
The thing is that every 20th bottle that passes the system, the arduino is going to play a "cheers" sound.

here is my current code:

#include "Ultrasonic.h"

long counter = 1;
int mem = 0;

Ultrasonic ultrasonic(2, 3); //(trig, echo)

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  mem = ultrasonic.Ranging(CM);
  
  if(ultrasonic.Ranging(CM) <= 15 && mem >= 15 ) { 
      Serial.print(counter);
      Serial.println(" bottles collected");
      counter++;
      delay(1000);
  }
  
  

}

i could make something like

if(counter == 20 || counter == 40 || ....

but that would not be an optimized and clean code.
I want the arduino to give a signal every 20th bottle passing, but still the arduino have to keep track of how many bottles there hav been in total.

Use modulo. if(counter % 20 == 0) play tune. the tune will play any time counter is evenly divisible by 20.

Thanks! That's exactly what I needed! I totally forgot about modulo!

I totally forgot about modulo!

You should also forget about that delay() in your code!