如果選取的數字不正確,我該如何讓程序從頭開始循環?我不確定我做錯了什麼。我試過if
S,do while
S,while
s和if else
S:隨機數生成器失敗
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ArrayProblms
{
class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Guess a number between 1 and 10: ");
RandomNumberGenerator();
Console.ReadLine();
}
public static void RandomNumberGenerator()
{
Random rand = new Random();
int userValue = int.Parse(Console.ReadLine());
int randValue = rand.Next(1, 11);
int attempts = 0;
if (userValue == randValue)
{
Console.WriteLine("You have guessed correctly!");
}
while (userValue != randValue)
{
Console.WriteLine("You have guessed incorrectly");
attempts++;
Console.WriteLine("You have made {0} incorrect guesses", attempts);
break;
}
}
}
}
什麼是結束該程序的條件,什麼連連條件遍歷? –