我写了一个程序在C#运行毕达哥拉斯定理。我希望能够让程序接受来自用户输入的小数点的帮助。这是我的。需要帮助,接受小数作为输入在C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Project_2
{
class Program
{
static void Main(string[] args)
{
int sideA = 0;
int sideB = 0;
double sideC = 0;
Console.Write("Enter a integer for Side A ");
sideA = Convert.ToInt16(Console.ReadLine());
Console.Write("Enter a integer for Side B ");
sideB = Convert.ToInt16(Console.ReadLine());
sideC = Math.Pow((sideA * sideA + sideB * sideB), .5);
Console.Write("Side C has this length...");
Console.WriteLine(sideC);
Console.ReadLine();
}
}
}
我一直在试图通过使用Math.Abs等仅用于接收构建错误来研究此问题。写道中的帮助将不胜感激。
使用Decimal.Parse()。 –
如果我使用那么Math.Pow功能停止工作,因为它无法转换双为十进制 – Thomas