Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

ARG help: Adding a Random Number Generator

+1 vote
asked Dec 1, 2022 by Sonata Avalon (130 points)

I'm currently making an ARG and am wondering how would I make the code below create two-five random number generations. Think that it could make like a number pad on a lock, you'd have to guess the number and if you succeed, it gives you a social media link that allows you to go deeper into the ARG.

/* rand example: guess the number */
#include <stdio.h>      /* printf, scanf, puts, NULL */
#include <stdlib.h>     /* srand, rand */
#include <time.h>       /* time */

int main ()
  int iSecret, iGuess;

  /* initialize random seed: */
  srand (time(NULL));

  /* generate secret number between 1 and 10: */
  iSecret = rand() % 10 + 1;

  do {
    printf ("Guess the number (1 to 10): ");
    scanf ("%d",&iGuess);
    if (iSecret<iGuess) puts ("The secret number is lower");
    else if (iSecret>iGuess) puts ("The secret number is higher");
  } while (iSecret!=iGuess);

  puts ("Congratulations!");
  return 0;

1 Answer

0 votes
answered Dec 3, 2022 by Peter Minarik (82,920 points)

To generate random numbers that are 2, 3, 4 or 5 digits long, I'd do the following:

    iSecret = rand() % 100000;
} while (iSecret <= 10);

I hope this helps.

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.