int randomtoguess = 0;
int x = 1;
int randomseed;
const int minnum = 1;
const int maxnum = 1000;
int innum;
int guessedtimes = 0;
int statusguess = 0;
bool isplaying = true;
char wanttoplay;
String outputnumbers = ((String) " The number is between " + minnum + " and " + maxnum);
void setup() {
Serial.begin(9600);
Serial.println("\n\n\n\n\n\n\n\n");
Serial.println("|----------------------------------|");
Serial.println(" Choose your first number to try\n to guess the secret number");
Serial.println(outputnumbers);
Serial.println("|----------------------------------|");
Serial.println("\n\n");
randomseed = random(1, 1000);
randomSeed(randomseed);
randomtoguess = random(minnum, maxnum);
randomseed = random(1, 1000) * randomtoguess;
randomtoguess = random(minnum, maxnum);
}
void loop() {
while (isplaying) {
if (Serial.available() > 0) {
innum = Serial.parseInt();
Serial.println(innum);
if (innum < randomtoguess) {
Serial.println("Too low.Try again.\n");
}
if (innum > randomtoguess) {
Serial.println("Too High.Try again.\n");
}
if (innum == randomtoguess) {
Serial.println("Congrats you made it.");
Serial.println("Do you want to guess another number?(y=YES, n=NO)\n");
guessedtimes = guessedtimes + 1;
statusguess = 1;
isplaying = 0;
}
while (statusguess) {
if (Serial.available()) {
wanttoplay = Serial.read();
if (wanttoplay == 'y') {
randomtoguess = random(minnum, maxnum);
Serial.println("You said YES");
Serial.println("Choose your first number to try\n to guess the random number\n\n\n\n");
Serial.println(outputnumbers);
isplaying = 1;
statusguess = 0;
}
if (wanttoplay == 'n') {
isplaying = 0;
Serial.println("You said NO");
Serial.print("You guessed ");
Serial.print(guessedtimes);
if (guessedtimes < 2) {
Serial.println(" number");
}
if (guessedtimes > 1) {
Serial.println(" numbers");
}
Serial.println("Bye bye.\n");
Serial.println("Remember if you want to play you can always press (y=YES)\n\n");
}
if (wanttoplay == 'Y') {
randomtoguess = random(minnum, maxnum);
Serial.println("You said YES");
Serial.println("Choose your first number to try\n to guess the random number\n\n\n\n");
Serial.println(outputnumbers);
isplaying = 1;
statusguess = 0;
}
if (wanttoplay == 'N') {
isplaying = 0;
Serial.println("You said NO\n");
Serial.println("You guessed " + guessedtimes);
if (guessedtimes < 2) {
Serial.print("number");
}
if (guessedtimes > 1) {
Serial.print("numbers");
}
Serial.println("Bye bye.\n");
Serial.println("Remember if you want to play you can always press (y=YES)\n\n");
}
}
}
}
}
}