Question

This is for a C# program. I would greatly appreciate any help! Thank you:)

For this assignment youre going to create a console application called A02PBallGenerator. This app is going to mimic a quick pick program in a lotto terminal. When the user runs your app youre going to select the numbers for them. Then you ask them if theyd like another set of numbers. Y for yes and N for No Use a do while loop so that if they type alowercase or uppercase y then you will give them a new set of numbers replacing the original ones. If they type anything else then exit the program. Powerball rules: In each game, players select five numbers from a set of 69 white balls and one number from 26 red Powerballs; the red ball number can be the same as one of the white balls. Your app is going to randomly choose five numbers from the white ball pool (1-69) and one from the red ball pool (1-26). Heres the catch, you cant repeat any of the white numbers. So if you find a duplicate then you have to keep choosing until you have a unique value. When you have your five unique values then Id like you to sort those values in ascending order. In other words, if your app chose 65, 2, 33, 14, 64 then you sort those so they show as 2, 14, 33, 64, 65. For the red ball you just randomly choose from 1-26 Here is a function that will return a number between (and including) the min and the max. So if you pass in 1 and 69 as arguments then youll get a number between (and including) 1 and 69 and youll get 1 to 26 (inclusive) if you pass in 1 and 26 for min and max. Leave the randomNumber declaration outside of the method. public static Random randomNumber new Random //Global, outside of any methods static int getRandomIntInclusive (int min, int max) return (randomNumber .Next (min max 1))

0 0
Add a comment Improve this question Transcribed image text
Answer #1

using System;
using System.Linq;

public class Test
{
   public static Random randomNumber = new Random();
   static int getRandomIntInclusive(int min,int max)
   {
       return (randomNumber.Next(min,max+1));
   }
   public static void Main()
   {
       int[] whiteBalls = new int[5];
       int redBall ;
       char option = 'y';
      
       do //loop to generate white balls and red ball
       {
          
       for (int i = 0; i < 5; i++) //generate 5 red balls
       {
        int wBall;
      
        do   // do while loop to generate 5 white balls until the ball number is repeated
        {
            wBall = getRandomIntInclusive(1,69);        //1-69 for the white balls
        }while(whiteBalls.Contains(wBall)); //no duplicate values

        whiteBalls[i] = wBall;
       }
       Array.Sort(whiteBalls);   //sorting the generated numbers
       redBall = getRandomIntInclusive(1,26);
      
       Console.WriteLine("White Balls");
       for (int i = 0; i < 5; i++)
       Console.WriteLine(whiteBalls[i]); //display white balls
      
       Console.WriteLine("Red Ball");
       Console.WriteLine(redBall); //display red ball
      
       Console.WriteLine("Do you want to have another set of numbers?");
       option = Convert.ToChar(Console.Read());
       }while(option == 'Y' || option == 'y');
   }
}

Output:

White Balls
9
12
30
58
59
Red Balls
8
Do you want to have another set of numbers?y
White Balls
3
28
39
42
63
Red Balls
1
Do you want to have another set of numbers?n
Add a comment
Know the answer?
Add Answer to:
This is for a C# program. I would greatly appreciate any help! Thank you:) For this...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT