Results 1 to 29 of 29

Thread: Lottery Program

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2003
    Location
    Eden Prairie Minnesota
    Posts
    301

    Lottery Program

    Code:
    /* Make a lottery program
       Picks 7 random numbers
       Asks the user for 7 numbers
       Checks how many match
       they can be in any order, like the first number the user chooses can match the 4th random number
       And all the random numbers have to be different
    */
    using System;
    
    namespace Lottery
    {
    	class Test
    	{
    		static void Main() 
    		{			
    			Console.Write("Welcome To Lottery, would you like to play? (yes/no) ");
    			string answer = Console.ReadLine();
    			if (answer == "yes") {
    				Console.WriteLine("Selecting Numbers at Random...");
    				Random rand = new Random();
    				int [] number;
    				number = new int[6];
    
    				for( int i = 0; i < 7; i++ )
    				{
    					number[i] = rand.Next(1, 49);
    				}
    
    				Console.WriteLine("Numbers have been selected!");
    			}
    			else {
    				Console.WriteLine("Thanks Anyways!");
    				Console.ReadLine();
    			}
    		}
    	}	
    }
    That's what i have so far.

    I am trying to check if any of the numbers randomly generated are duplicates and then replace them if they are. However, i have been unableto accomplish this, so any help would be appreciated.

    If you have any suggestions on how to improve on my code that would be very helpfull.

    Thank You

    - Joel
    Last edited by BaDDBLooD; Dec 3rd, 2005 at 01:34 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width