CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Threaded View

  1. #1
    Join Date
    Dec 2011
    Posts
    1

    C# Lottery console application NEED HELP!

    Hello, I am having problem with my console application. I don't know how to check if my inputted numbers matches with the random number generator. Also I don't know how to specify the inputted number that matches the number matches prize draw. Here is my code.

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    
    namespace random
    {
        class Program
        {
            static void Main(string[] args)
            {
                // declaring integers
                int iNum1;
                int iNum2;
                int iNum3;
                int iNum4;
                int iNum5;
                int iNum6;
                int iCount = 0;
                int iGuess;
                int iRandom;
                int iAmount;
                // declaring constants
    
                const int iBALLS = 6;
                const int iMATCHONE = 10;
                const int iMATCHTWO = 20;
                const int iMATCHTHREE = 40;
                const int iMATCHFOUR= 80;
                const int iMATCHFIVE = 140;
                const int iMATCHSIX = 1000;
    
                // array
                
    
                // generating random numbers
    
                Random randomnumber = new Random();
    
                iNum1 = randomnumber.Next(1, 49);
                iNum2 = randomnumber.Next(1, 49);
                iNum3 = randomnumber.Next(1, 49);
                iNum4 = randomnumber.Next(1, 49);
                iNum5 = randomnumber.Next(1, 49);
                iNum6 = randomnumber.Next(1, 49);
    
                iRandom = iNum1 + iNum2 + iNum3 + iNum4 + iNum5 + iNum6;
    
                for (iCount = 0; iCount < iBALLS; iCount++)
                {
                    
                    Console.Write("No:" + (iCount + 1) + " Choose your number: ");
                    iGuess = Convert.ToInt32(Console.ReadLine());
                    
    
                    while (iGuess < 1 || iGuess > 10)
                    {
                        Console.WriteLine("You have entered an incorrect number please try again");
                        iGuess= Convert.ToInt32(Console.ReadLine());
    
                    }
    
                    iAmount = 0;
    
                    if (iGuess == iNum1)
                    {
                        Console.WriteLine("you won $" + iMATCHONE);
                        Console.WriteLine();
                        Console.WriteLine("Press any key to continue");
                        Console.ReadKey();
                        iAmount++;
                    }
    
    
                    if (iGuess == iNum2)
                    {
                        Console.WriteLine("you won $" + iMATCHTWO);
                        Console.WriteLine();
                        Console.WriteLine("Press any key to continue");
                        Console.ReadKey();
                        iAmount++;
                    }
    
                    if (iGuess == iNum3)
                    {
                        Console.WriteLine("you won $" + iMATCHTHREE);
                        Console.WriteLine();
                        Console.WriteLine("Press any key to continue");
                        Console.ReadKey();
                        iAmount++;
                    }
    
                    if (iGuess == iNum4)
                    {
                        Console.WriteLine("you won $" + iMATCHFOUR);
                        Console.WriteLine();
                        Console.WriteLine("Press any key to continue");
                        Console.ReadKey();
                        iAmount++;
                    }
    
    
                    if (iGuess == iNum5)
                    {
                        Console.WriteLine("you won $" + iMATCHFIVE);
                        Console.WriteLine();
                        Console.WriteLine("Press any key to continue");
                        Console.ReadKey();
                        iAmount++;
                    }
    
    
                    if (iGuess == iNum6)
                    {
                        Console.WriteLine("you won $" + iMATCHSIX);
                        Console.WriteLine();
                        Console.WriteLine("Press any key to continue");
                        Console.ReadKey();
                        iAmount++;
                    }
    
    
                    Console.WriteLine("you have matched " + iAmount + " numbers");
                }
    
    
    
                Console.WriteLine("The numbers are " + iNum1 + ", " + iNum2 + ", " + iNum3 + ", " + iNum4 + ", " + iNum5 + ", " + iNum6 + ", ");
                Console.ReadKey();
    
    
            }
        }
    }
    Last edited by cjard; December 3rd, 2011 at 06:08 AM.

Tags for this Thread

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

Featured