0
C#으로 주사위 시뮬레이터 프로그램을 만들었지 만 할당 요구 사항에서 사용자가 원하는만큼 반복 할 수 있어야한다고합니다.반복 프로그램 C#
그것은 파이썬에서 간단 :
def var():
import random
dicesides = int(input("Please enter the amount of sides you want the dice that is being thrown to have. The dice sides available are: 4, 6 and 12: "))
script(dicesides, random)
def script(dicesides, random):
if dicesides in (4,6,12):
dice = int(random.randrange(1, dicesides))
print(dicesides, " sided dice, score", dice)
else:
print("That number is invalid. Please try again.")
var()
repeat = str(input("Repeat? Simply put yes or no : "))
if repeat == "yes":
var()
else:
quit()
var()
그리고 이것은 내 C# 코드 :
static void Main(string[] args)
{
Random random = new Random();
int num;
Console.WriteLine("Please enter the amount of sides you want the dice that is being thrown to have. The dice sides available are: 4, 6 and 12: ");
num = Convert.ToInt32(Console.ReadLine());
if (num == 4 || num == 6 || num == 12)
{
int randomDice = random.Next(0, num);
Console.WriteLine(num + " sided dice thrown, " + randomDice);
}
else
{
Console.WriteLine("That number is invalid. Please try again.")
}
}
가 어떻게 프로그램이 반복 얻을 것?
분명히 루프가 필요합니다. –
그런데'random.Next()'를 호출하면 하한으로'1', 상한으로'num + 1'을 사용해야합니다 , 0에서 5로가는 D6을 시뮬레이트하지 않는 한 – StriplingWarrior
@DStanley : 출구 조건이 충족 될 때까지 프로세스를 반복하는 것과 같은 일을 여전히 수행합니다. 어떻게 끝났는 지 상관없이 루프입니다. 필자와의 유사점은 매우 분명하며 한 줄의 파이썬 코드를 작성한 적이 없다. "반복해서 ..."또는 "이 조건이 존재하는 동안"은 매우 분명합니다. –