I like to play games

Understood, I'll provide explanations for each step in C.

#include <stdio.h>

int main() {
    int secretNumber = 7;
    int guess;

    do {
        printf("Guess the secret number: ");
        scanf("%d", &guess);

        if (guess < secretNumber) {
            printf("Too low! Try again.\n");
        } else if (guess > secretNumber) {
            printf("Too high! Try again.\n");
        } else {
            printf("Congratulations! You guessed the secret number.\n");
        }
    } while (guess != secretNumber);

    return 0;
}

Explanation:

  1. #include <stdio.h>: Includes the standard input-output library for basic input and output operations.
  2. int main() { ... }: The main function where the program execution starts.
  3. int secretNumber = 7;: Declares a variable secretNumber and assigns it the value 7.
  4. int guess;: Declares a variable guess without initializing it.
  5. do { ... } while (guess != secretNumber);: Initiates a do-while loop that continues until the guess matches the secretNumber.
  6. printf("Guess the secret number: ");: Prompts the user to input a guess for the secret number.
  7. scanf("%d", &guess);: Reads the user input as an integer and stores it in the guess variable.
  8. if (guess < secretNumber) { ... } else if (guess > secretNumber) { ... } else { ... }: Checks if the guess is lower, higher, or equal to the secretNumber and provides appropriate feedback.
  9. If the guess is lower than the secretNumber, it prints "Too low! Try again." If the guess is higher, it prints "Too high! Try again." If the guess matches the secretNumber, it prints "Congratulations! You guessed the secret number."
  10. The loop continues until the correct secretNumber is guessed.
  11. return 0;: Indicates successful termination of the main function.