How do you plan to solve it?
/*Paste your code here*/
#include <EEPROM.h>
#define MAX_SCORES 5
int scores[MAX_SCORES];
int targetNumber;
int attempts;
void loadScores() {
for (int i = 0; i < MAX_SCORES; i++)
EEPROM.get(i * sizeof(int), scores[i]);
// If uninitialized EEPROM, fill with max int
for (int i = 0; i < MAX_SCORES; i++)
if (scores[i] <= 0 || scores[i] > 10000)
scores[i] = 9999;
}
void saveScores() {
for (int i = 0; i < MAX_SCORES; i++)
EEPROM.put(i * sizeof(int), scores[i]);
}
void insertScore(int newScore) {
for (int i = 0; i < MAX_SCORES; i++) {
if (newScore < scores[i]) {
for (int j = MAX_SCORES - 1; j > i; j--)
scores[j] = scores[j - 1];
scores[i] = newScore;
break;
}
}
saveScores();
}
void printLeaderboard() {
Serial.println("\n📌 Leaderboard (Least Attempts = Best)");
for (int i = 0; i < MAX_SCORES; i++) {
if (scores[i] == 9999)
Serial.println(String(i + 1) + ". ---");
else
Serial.println(String(i + 1) + ". " + String(scores[i]) + " attempts");
}
Serial.println("----------------------------------\n");
}
void startNewGame() {
targetNumber = random(1, 101);
attempts = 0;
Serial.println("\n🎮 New Game Started!");
Serial.println("Guess a number between 1 and 100:\n");
}
void setup() {
Serial.begin(9600);
randomSeed(analogRead(0));
loadScores();
startNewGame();
}
void loop() {
if (Serial.available()) {
int userGuess = Serial.parseInt();
if (userGuess <= 0) return;
attempts++;
if (userGuess > targetNumber) {
Serial.println("⬆ Too High! Try again...");
} else if (userGuess < targetNumber) {
Serial.println("⬇ Too Low! Try again...");
} else {
Serial.println("\n🎉 Correct Guess!");
Serial.println("🔢 Number = " + String(targetNumber));
Serial.println("📌 Attempts = " + String(attempts));
// Save and show Leaderboard
insertScore(attempts);
printLeaderboard();
delay(1000);
startNewGame();
}
}
}
Add a video of the output (know more)
Add a photo of your hardware showing the output.

Add a Screenshot of the serial terminal showing the output.