我寫了一個程序在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