gpt4 book ai didi

c# - 如何在 C# 中使用字符串和 double 获取二维数组的用户数据?

转载 作者:太空宇宙 更新时间:2023-11-03 12:06:21 25 4
gpt4 key购买 nike

我目前有一个二维字符串数组的代码,用于保存一周中的 5 天和 5 个数值。请注意,这是在 C# 的控制台应用程序中。

我唯一的问题是在用户端输入数据有点困惑,因为就目前而言,我必须连续输入所有 10 个数据值;天数与数字没有区别。

我希望在用户输入前 5 天后出现对话,告诉他们现在输入数值数据。

有什么不同的方法可以做到这一点?

当前代码如下所示。

  //Ask the user to enter five days of the week and rainfall data for each day
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine("\n5. Please enter five days of the week.");

//Store the data in a two dimensional string array named rainfallData[]
Console.ForegroundColor = ConsoleColor.White;
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 5; j++)
{
rainfallData[i, j] = Console.ReadLine();
}
}
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine("Doubles placed in myDoubles[] array.");
Console.ForegroundColor = ConsoleColor.White;
for (int i = 0; i < 2; i++)
{
Console.WriteLine();
for (int j = 0; j < 5; j++)
{
Console.WriteLine("rainfallData({0},{1})={2}", i, j, rainfallData[i, j]);
}
}

最佳答案

要在输入前 5 条消息后显示一条消息,请添加一个额外的 if 语句和控制台输出。

for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 5; j++)
{
rainfallData[i, j] = Console.ReadLine();
}

if(i == 0)
{
Console.WriteLine("Enter rain data");
}

关于c# - 如何在 C# 中使用字符串和 double 获取二维数组的用户数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54718505/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com