我必须找到一个数字的平方/ 12345/- 完成了。我想使程序有点复杂,我有这样的:C#找到一个数字的平方
using System;
class Program
{
static void Main()
{
Console.WriteLine("The square of the number 12345 is");
Console.WriteLine(Math.Sqrt(12345));
Console.WriteLine("Enter a number to calculate the square:");
int numVal = int.Parse(Console.ReadLine());
Console.WriteLine("The square of your number is" + " " + Math.Sqrt(numVal));
Console.WriteLine("Do you wish to enter another number? Yes/No");
string input = Console.ReadLine();
if (input == "Yes")
{
Console.WriteLine("Enter a number to calculate the square:");
int newNum = int.Parse(Console.ReadLine());
Console.WriteLine("The square of your number is" + " " + Math.Sqrt(newNum));
}
else
{
Console.WriteLine("Have a nice day!");
}
}
}
现在有这样的问题:程序询问时,如果我想进入另一个号码,答案应该是用大写字母/是的,没有/。即使我以小写字母输入answear,是否有办法使其工作?/是,否/?
你想的方形或平方根? [Math.Sqrt](https://msdn.microsoft.com/en-us/library/system.math.sqrt(v = vs.110).aspx) –
尝试使用'IndexOf'方法中的'OrdinalIgnoreCase',而不是比较'=='运算符。 –
尝试 input.toLowerCase == “是” http://stackoverflow.com/questions/6371150/comparing-two-strings-ignoring-case-in-c-sharp – Blinky