This is for a C# program. I would greatly appreciate any help! Thank you:) For t
ID: 3791272 • Letter: T
Question
This is for a C# program. I would greatly appreciate any help! Thank you:)
For this assignment you're 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 you're going to select the numbers for them. Then you'll ask them if they'd like another set of numbers. Y for yes and N for No Use a do while loop so that if they type a lowercase 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. 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). Here's the catch, you can't 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 I'd like you to sort those values in ascending order. In other words, if your app chose 65, 2, 33, 14, 64 then you'll 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 you'll get a number between (and including) 1 and 69 and you'll get 1 to 26 (inclusive) if you pass in 1 and 26 for min and max. Leave the random Number declaration outside of the method. public static Random random Number = new Random ();//Global, outside of any methods. static int getRandomIntInclusive (int min, int max) return (randomNumber .Next (min max +1));Explanation / Answer
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:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.