これまでは、ランダムに生成された数字とユーザー入力の違いを見つけるのに苦労しました。私はちょっとした検索をして、を使うことができず、実際にはこれを使用しなければならないことがわかりました。int guess = Convert.ToInt32(Console.ReadLine());
私は偶然、それをConvert.ToInt32(Console.Read());
としました。私が自分自身を効果的に説明していないなら、私はコーディングに新しい人で、これは学ぶべきものであることを意味しました。ありがとう!誰かがなぜintに変換し、Readの代わりにread lineを使って私の問題を修正したのか説明できますか?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Would you like to play the guessing game?");
string input = Console.ReadLine();
if (input.Equals("yes"))
{
Console.WriteLine("Alright! The rules are simple, i'll think of a number and you guess it!");
Console.WriteLine("Alright enter your guess: ");
int guess = Convert.ToInt32(Console.ReadLine());
Random rand = new Random();
int answer = rand.Next(1,11);
if (rand.Equals(guess))
{
Console.WriteLine("Congratulations you guessed correctly!");
}
else
{
Console.WriteLine("Aww you were so close! I guessed " + answer);
int difference = guess - answer;
Console.WriteLine("you were only " + Math.Abs(difference) + " away");
}
} else
{
Console.WriteLine("Closing application...");
Thread.Sleep(1000);
Environment.Exit(0);
}
}
}
}
甘い、私はASCII値についても考えなかった。ありがたいことに私はあなたがハハについて話していることを知っています。 – Zech