【发布时间】:2016-08-25 21:20:30
【问题描述】:
如果选择了不正确的数字,如何让程序从头开始循环?我不确定我做错了什么。我试过ifs、do whiles、whiles 和if elses:
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;
}
}
}
}
【问题讨论】:
-
程序结束的条件是什么,反复循环的条件是什么?
标签: c# linq visual-studio functional-programming