Your state is in a process of creating a weekly lottery. Oncea week, five distin
ID: 3610366 • Letter: Y
Question
Your state is in a process of creating a weekly lottery. Oncea week, five distinct randon integers between 1 to 40 (inclusive)are drawn. If a player guesses all the numbers correctly; theplayer wins a certain amount. Write a program that does thefollowing: (a) Generates five distinct randon numbers between 1 to 40(inclusive) and stores them in an array. (b) Sort the array containing the lottory numbers. (c) Prompts the player to select five distinct integersbetween 1 and 40 (inclusive) and stores the numbers in an array. The player canselect the numbers in any order and the array containing thenumbers need not be sorted. (d) Determines whether the player guessed the lottery numberscorrectly. If the player guessed the lottery numbers correctly, itwill output the message "You Win!"; otherwise it outputs themessage "You Lose!" and output the lottory numbers. Your program should allow the player to play the game asmany times as the player want to play. Before each play, generate anew set of lottery numbers. Use Functions, Struct and int main calls functiononly.(not only but mainly). No vector. Your state is in a process of creating a weekly lottery. Oncea week, five distinct randon integers between 1 to 40 (inclusive)are drawn. If a player guesses all the numbers correctly; theplayer wins a certain amount. Write a program that does thefollowing: (a) Generates five distinct randon numbers between 1 to 40(inclusive) and stores them in an array. (b) Sort the array containing the lottory numbers. (c) Prompts the player to select five distinct integersbetween 1 and 40 (inclusive) and stores the numbers in an array. The player canselect the numbers in any order and the array containing thenumbers need not be sorted. (d) Determines whether the player guessed the lottery numberscorrectly. If the player guessed the lottery numbers correctly, itwill output the message "You Win!"; otherwise it outputs themessage "You Lose!" and output the lottory numbers. Your program should allow the player to play the game asmany times as the player want to play. Before each play, generate anew set of lottery numbers. Use Functions, Struct and int main calls functiononly.(not only but mainly). No vector.Explanation / Answer
Dear..
Am giving you the sample one of lottery sourcecode.
namespace Lottery
{
using System;
using System.Collections;
public class Lottery
{
public static int Numbers,EndRange;
public static voidDisplayTitles()
{
EndRange=0;
Numbers=1;
while(EndRange<Numbers)
{
System.Console.WriteLine(" ");
System.Console.WriteLine("Lottery number generator");
System.Console.WriteLine("");
System.Console.Write("How manyunique numbers? : ");
Numbers=Convert.ToInt32(System.Console.ReadLine());
System.Console.Write("Enterend range : ");
EndRange=Convert.ToInt32(System.Console.ReadLine());
}
}
public static void GenerateNumbers(Stack s, Dice d)
{
bool exists=true;
int i;
int val;
for(i=1;i<=Numbers;i++)
{
val=d.RollDice(EndRange);
exists=s.Contains(val);
while (exists==true)
{
val=d.RollDice(EndRange);
exists=s.Contains(val);
}
s.Push(val);
}
}
public static void DisplayResults(Stack s)
{
for (inti=1;i<=Numbers;i++)
{
System.Console.WriteLine(s.Pop());
}
}
public static int Main (string[] args)
{
Stack s = new Stack();
Dice d = new Dice();
DisplayTitles();
GenerateNumbers(s,d);
DisplayResults(s);
return 0;
}
}
public class Dice
{
public int RollDice(intsides)
{
Random r =new Random();
int i=0;
while(i==0)
{
i=r.Next(sides+1);
}
return i;
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.