Error checking is significantly easier if you encapsulate your code (preferably avoiding Russian doll ideograms).
Two ways to approach the problem, which depends on your preference: C programming style (stand alone, independent functions) or C++ (class based functions).
Something like:
class Button
{
public:
sf::IntRect Box; //This could easily be protected or private
const bool IsClicked(const sf::Mouse Mouse, const float X, const float Y)
{
//We check if it's clicked first because a direct value comparison is less resource intensive than an area check
if(!Mouse.isButtonPressed(sf::Mouse::Left)){return false;}
//It's pressed! Let's check it's actually in the box:
return Box.contains(X,Y);
}
};
That's just an idea. You could alternately make it so the function takes both the window and mouse as an argument and does all the leg work of figuring out if the mouse has clicked on it, itself (although it'd be highly inefficient for, say, 80+ buttons to ALL check the button has been clicked, and be easier to just use rect's 'contains' in a for() loop function inside a clicked button if statement).
Don't worry about efficiency at this stage, just get the idea working then prune and improve it afterwards.