简体   繁体   中英

C# Take user input and makes a selection from groupd of numbers

I am trying to help my dad making a Lottery program.

My dad is making calculations over a period of 52 weeks. When he has the calculations he has 3 groups of numbers

Group1 is: 1-12 Group2 is: 13-25 Group3 is: 26-35

When he makes his calcualtions he looks a the Lottery the past 52 weeks and lets say 4 numbers has been most present the past 52 weeks from Group1, and 2 numbers from Group2 and 1 from Group3. In Denmark our Lottery system has 7 numbers in Total.

So I have made a program which prompts him for X amount of numbers in group1 and then Group2 and then Group3..

But my problem is, I´m struggling with the random selection in each group from the Numbers he is choosing.

Lets say he choose 3 numbers from Group1, then he wants it to randomly select 3 numbers from the range 1-12 , so it could be 4, 10 and 11 and then he select 2 from group2 range 13-25 , so it could be 17, 20 and so on..

But I really struggling here with the last piece of code, I'm using Visual Studio 2022 and I´m working in C# App net.frame

This is how my code looks at the moment and this is where I get stuck

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LottoProgramFinal
{
    internal class Program
    {
        static void Main(string[] args)
        {

            Random random = new Random();


            // Headline and Welcome Text
            Console.WriteLine( "\n\n\n\t --------------------------------", Console.ForegroundColor = ConsoleColor.Yellow);
            Console.WriteLine( "\t  Lotto Generator Copyright 2022 " );
            Console.WriteLine( "\t --------------------------------" );
            Console.ResetColor();
            Console.WriteLine( "\n\n\n Vælg nu de antal tal i hver enkelt Gruppe: ");

            // User input Selection in Group1
            Console.Write( "\n\n Indtast antal tal fra Gruppe 1:  ");
            int Gruppe1 = Convert.ToInt32( Console.ReadLine() );
            Console.WriteLine("\n Du har valgt: {0} tal fra Gruppe 1 ", Gruppe1);
            
            // User input selection in Group2
            Console.Write( "\n\n Indtast antal tal fra Gruppe 2:  ");
            int Gruppe2 = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine( "\n Du har valgt: {0} tal fra Gruppe 2 ", Gruppe2);
            
            // User input selection in group3
            Console.Write( "\n\n Indtast antal tal fra Gruppe 3:  ");
            int Gruppe3 = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine( "\n Du har valgt: {0} tal fra Gruppe 3", Gruppe3);

            
            Console.WriteLine("\n De valgte tal i gruppe 1 er {0}");

            Console.ReadKey();

Perhaps some form of loop that prints out the results would help:

            //...

            // User input Selection in Group1
            Console.Write( "\n\n Indtast antal tal fra Gruppe 1:  ");
            int Gruppe1 = Convert.ToInt32( Console.ReadLine() );
            Console.WriteLine("\n Du har valgt: {0} tal fra Gruppe 1 ", Gruppe1);
            
            
            for(int i = 0; i < Gruppe1; i++) {
                // print to console a random number in group 1 range (1,12)
                Console.WriteLine(random.Next(1,13)); // random.next is 1 INclusive to 13 EXclusive, it doesn't include 13
            }

            //...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM