【发布时间】:2017-01-30 04:25:33
【问题描述】:
我正在尝试创建一个不使用生成 5 个随机数 1-9 的数组的策划游戏,你有 15 次尝试猜测它们。*=正确 -=错误 +=位置不正确,但数字是正确的。
我创建了它的第一部分,它用于尝试猜测 1-9 的第一个随机数字。我不确定如何转到第二个数字让玩家猜测第二个 1-9 数字,以及如何使代码继续使用相同的整数/继续添加到我已经设置的猜测中。我尝试了所有我知道的方法,但我无法弄清楚。如果我能在哪里出错以及如何正确设置它得到一些帮助,我将不胜感激。干杯
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Decisions
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Guess the 5 Digit code, Under 15 tries!");
Random myRandom = new Random();
Int32 one = myRandom.Next(1, 10);
Int32 two = myRandom.Next(1, 10);
Int32 three = myRandom.Next(1, 10);
Int32 four = myRandom.Next(1, 10);
Int32 five = myRandom.Next(1, 10);
int guesses = 0;
bool incorrect = true;
do
{
if (guesses < 15)
Console.WriteLine("Guess a number between 1 and 9");
string result = Console.ReadLine();
guesses++;
if (guesses > 15)
Console.WriteLine("You went over 15 tries! Better luck next time");
if (result == one.ToString())
incorrect = false;
else if (result == two.ToString())
Console.WriteLine("+");
else if (result == three.ToString())
Console.WriteLine("+");
else if (result == four.ToString())
Console.WriteLine("+");
else if (result == five.ToString())
Console.WriteLine("+");
else
Console.WriteLine("-");
} while (incorrect);
if (guesses < 15)
Console.WriteLine("*Correct! It took {0} guesses.", guesses);
if (guesses > 15)
Console.WriteLine("You took to many tries! Better luck next time! Total Guesses: {0}", guesses);
Console.ReadLine();
}
}
}
【问题讨论】:
-
为什么不想使用数组?
-
为什么不使用数组?你也用指甲刀修剪草坪吗?
-
这是一个你应该使用列表而不是数组的家庭作业吗?
-
@chadnt 是的,而且我的教授在给出指示方面几乎没有用处,只是在尝试过渡到猜测下一个数字时我出错的地方需要一些帮助。
-
@Yukon,他们必须按顺序猜吗?
标签: c#