【发布时间】:2022-08-02 16:49:02
【问题描述】:
我在做一个乐透数组游戏,我想在数组中写入 10 个不同的数字,看看我是否得到宾果游戏。我希望它是二维的,并且我的大部分代码都是正确的(我已经在 1D 中尝试过),但是就像我将它更改为 2D 一样,我遇到了数组(数组 [i])的问题,我没有不知道为什么,我找不到任何问题的答案。请帮忙。 这是代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace kents.lottospel
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(\"skriv in nummer\");
//2D array
int[,] array = new int[2, 5];
for (int i = 0; i < array.GetLength (0); i++)
{
//print in numbers
Console.WriteLine(\"skriv in lottoboll nummer\" + \" \" + i + \":\");
array[i] = int.Parse(Console.ReadLine()); //this is one problem i have
(the array[i])
}
Random rand = new Random();
int randNum = rand.Next(1, 20);
for (int j = 0; j < array.GetLength (0); j++)
{
if (array[i] == randNum) //and this is also one problem (array[i])
{
Console.WriteLine($\"Bing!\\nDet rätta talet var\" + \" \" + randNum);
break;
}
else
{
Console.WriteLine($\"tyvärr men du har inte fått nån bingo denna
gången\");
}
}
Console.WriteLine($\"boll nummer\" + \" \" + randNum + \" \" + \"gav bingo\");
Console.WriteLine(\"slut på spelet.\");
}
}
}
-
二维数组需要用 2 个值索引
标签: c#