Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8731259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:11:44+00:00 2026-06-13T09:11:44+00:00

I’ve been having some trouble with a guessing game that populates an array with

  • 0

I’ve been having some trouble with a guessing game that populates an array with random integers, and then has the user try to guess a number in the array. I believe I have most of it correct, but the program will not go beyond the “Initializing lucky numbers…” print command for me to check whether my functions are working or not. I believe the problem either lies with how I’m passing the array to the functions, or how I’m calling the functions (perhaps in their prototypes?) Any help would be greatly appreciated.
This is my first post, so I apologize if I was unable to correctly include the code. Thank you!

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>

/*
This program is a lucky number guessing game. A series of unique, random numbers 
will be generated and stored in an array. Users will have up to three chances to
guess a number stored in the array.*/

//Function Prototypes
int fillArray (int,int []);
int searchArray (int, int []);
int printArray (int, int []);

int main(){
 const int MAX = 25;
 int iArray[MAX]={0};
 int count;

 printf("Initializing lucky numbers...");
 //printf("%d", iArray[0]);
 //for(count=0;count<MAX;count++){
   //printf("%d ",iArray[count]);
 //}//end for loop
 fillArray(MAX,iArray);
 //ONLY TO CHECK ARRAY CONTENTS
 //printf("%d",iArray[0]);
 //for(count=0;count<MAX;count++){
 //  printf("%d ",iArray[count]);
 //}//end for loop
 //CARRY ON WITH PROGRAM
 searchArray(MAX,iArray);

 getch();
 return 0;   
}

//Function Definitions

//Fill Array Function
int fillArray(int max,int Array[]){
    int i;
    int j;
    int uniqueFlag;
    int random;
    srand(time(NULL));

    for(i = 0; i < max; i++) {
     /* Assume things are unique... we'll reset this flag if not. */
     uniqueFlag = 1;
     do {
        random = (rand() % 101);
        /* This loop checks for uniqueness */
        for (j = 0; j < i && uniqueFlag == 1; j++) {
           if (Array[j] == random) {
              uniqueFlag = 0;
           }//end if statement
        }//end for loop
     } while (uniqueFlag != 1);
     Array[i] = random;
}//end while
//ONLY TO CHECK ARRAY CONTENTS
printf("%d",Array[0]);
printf("\n%d\n",Array[1]);
for(i=0;i<max;i++){
  printf("%d ",Array[i]);
}//end for
}//end function

//Search Array Function
int searchArray(int max, int Array[]){
    int i;
    int guessCounter=0;
    int iGuess;
    do{
       printf("Please guess a number between 0 and 100: ");
       scanf("%d",&iGuess); 
       for(i=0;i<max&&guessCounter<3;i++){
          if(Array[i] == iGuess){
              printf("Correct");
              guessCounter = 3;
              }//end if
          else{
               printf("%d is not one of the lucky numbers.\n",iGuess);
               guessCounter++;
               }//end else
               }//end for
    }while(guessCounter < 3); //end do-while loop
    if(guessCounter==3){
        printf("Sorry! You lose!\n");
        printArray(max, Array);
        }//end if
}//end function   

//Print Array Function
int printArray(int max, int Array[]){
    int i;
    printf("Array contents: ");
    for(i=0;i<max;i++){
       printf("%d ",Array[i]);
    }//end for
}//end function
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:11:45+00:00Added an answer on June 13, 2026 at 9:11 am

    uniqueFlag needs to be reset whenever you pick a random number, not just at the start of the outer loop in fillArray.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have an array which has BIG numbers and small numbers in it. I
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a jquery bug and I've been looking for hours now, I can't
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a small JavaScript validation script that validates inputs based on Regex. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.