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 8846457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:59:25+00:00 2026-06-14T11:59:25+00:00

I am creating a lottery game in C++. I created a function called GetLottoPicks

  • 0

I am creating a lottery game in C++.
I created a function called GetLottoPicks which asks the user for 7 numbers.
I have another function called GenWinNums that generates 7 random numbers.

The problem is for the GenWinNums it keeps generating this 7 times: -858993460

I believe I made inputs into the argument int WinningNums[] bu apparently not?

Thank you.

int main()
{
string name;
int choice;
int user_picked[7];
int chosen_lotto[7];

cout << "LITTLETON CITY LOTTO MODEL:" << endl;
cout << "---------------------------" << endl;
cout << " 1) Play Lotto " << endl;
cout << " Q) Quit Program " << endl;
cout << " Please make a selection: ";
cin >> choice;

if (choice == 1)
{
    cout << "\n Please enter your name: ";
    cin >> name;

    getLottoPicks(user_picked);
    GenWinNums(chosen_lotto);

    for(int i = 0; i < 7; i++)
    {
        cout << chosen_lotto[i];    
    }

    for(int i = 0; i < 7; i++)
    {
        cout << user_picked[i];
    }
}

else if (choice == 'Q' || 'q')
{
    exit(0);
}

else 
{
    cout << "That is not a valid choice." << endl;
}

 system("PAUSE");
 return 0;
 }

 int getLottoPicks(int UserTicket[])
 {   
const int amount = 7;
UserTicket[amount];
int ticket = UserTicket[amount];

for (int i = 0; i < amount; i++)
{
    cout << "\n Please enter number " << i + 1 << ":";
    cin >> UserTicket[i];

    while (UserTicket[i] < 1 || UserTicket[i] > 40)

    {
        cout << "Your selection cannot be less than 1 and/or greater than 40. Try Again." << endl;
        cin >> UserTicket[i];
    }

if(i > 0)
    {
        for(int check = 0; check < i; check++)
        {
            while(UserTicket[i] == UserTicket[check])
            {
                cout << "You cannot use the same lotto number twice. Try again: " << endl;
                cin >> UserTicket[i];
            }
        }
}

}

return ticket;
 }

 int GenWinNums(int WinningNums[])
 {
const int amount = 7;
int numbers[amount];
int ticket = WinningNums[amount];

for(int i = 0; i < amount; i++)
{
    numbers[i] = (rand() % 40) + 1;

    while(numbers[i] < 1 || numbers[i] > 40)
    {
        numbers[i] = (rand() % 10) + 1;
    }
    if(i > 0)
    {
        for(int check = 0; check < i; check++)
        {
            while(numbers[i] == numbers[check])
            {
                numbers[i] = (rand() % 10) + 1;
            }
        }
    }
}
return ticket;
 }
  • 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-14T11:59:26+00:00Added an answer on June 14, 2026 at 11:59 am

    Looks like you are never assigning any values to the WinningNums array in your routine, that might explain why you get the same number all the time.

    I’d suggest removing the numbers array and working directly with WinningNums to generate your random numbers.

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

Sidebar

Related Questions

Possible Duplicate: Generate unique random numbers in Java I am creating a lottery app
Creating an installer for possible remote systems so that if they do not have
Creating liquid layouts is an immense pain. Now, I totally understand that tables should
Creating a google map with store locations within 50 miles of user entered address.
Creating a JApplet I have 2 Text Fields, a button and a Text Area.
Creating a simple RPG game, first time using XNA. Trying to get my character
I creating a web application using JSF,Hibernate,Spring. I have added a filter for checking
Creating a Blackberry app. Just a beginner, I have searched but couldn't find a
Creating function to print question, add choices to a list. def print_et_list (): answer_list
Creating a Drawable that is completely empty seems like a common need, as a

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.