Advertisement
C_Volume2 Complete Applications #82329

A Very Simple Number Guessing Game

The Number Guessing Game will generate a number between 1 and 100. The user will have infinite attempts to guess the number.

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
 int n;
 int num;
 srand(time(NULL)); //generate the random seed generator
 n = 1 + rand() % 100; //pick a number from 1 to 100
 printf("\nI have a number between 1 and 100\n");
 printf("Can you guess my number?\n");
 printf("Please type your first guess.\n");
 scanf("%d", &num);
 
 while (n != num){
   if (num > n){
      printf("Too High! Try again!\n");
      scanf("%d", &num);
     }
   else
   if (num < n){
      printf("Too Low! Try again!\n");
      scanf("%d", &num);
      }
   }/*end of while loop*/
      printf("Excellent! You guessed the number!\n");
    return 0;
}
Original Comments (3)
Recovered from Wayback Machine