{}
BLACK NOVEMBER
Are you struggling to build your coding confidence or land your first job? Fast-track to your first pay-check. Start PRO
BLACK NOVEMBER
Fast-track to your first pay-check. Start PRO
run-icon
main.c
#include <stdio.h> #include <stdlib.h> #include <time.h> int main() { int secretNumber, guess, attempts = 0; // Seed the random number generator srand(time(NULL)); secretNumber = rand() % 100 + 1; // Secret number between 1 and 100 printf("🎉 Welcome to the Number Guessing Game!\n"); printf("I have selected a number between 1 and 100.\n"); printf("Can you guess it?\n"); do { printf("Enter your guess: "); scanf("%d", &guess); attempts++; if (guess > secretNumber) { printf("Too high! Try again.\n"); } else if (guess < secretNumber) { printf("Too low! Try again.\n"); } else { printf("🎊 Congratulations! You guessed it in %d attempts.\n", attempts); } } while (guess != secretNumber); return 0; }
Output