Any Mac that can run Yosemite can also run at least El Capitan, and possibly newer depending on the Mac model and its model year.
You can try using the newest-version path into macOS Recovery, though this Mac may be too old for that. Try “Option-Command-R during startup, in most cases you're offered the latest macOS that is compatible with your Mac.”
Use another Mac, and download the newest macOS version supported by your Mad, and use that to build a bootable installer, then transfer that to the Mac and install.
Click or tap > How to create a bootable installer for macOS - Apple Support
To get the macOS installer, use Safari for the download, and see > How to get old versions of macOS - Apple Support
One problem that can lead folks into trying to do a re-install can be failing hardware, and particularly a failing hard disk, too.