因此,在這個代碼我試圖讓這個如果用戶輸入一個值超出範圍就會顯示消息:調整控制檯apliacation(trycatch和while循環)
輸入一個有效的輸入(在1和2^53之間)
它現在在做什麼是當你輸入一個字母時出現消息,但是當你輸入一個小於0的數字時,它會重置循環,並繼續,如果沒有發生。
//variables
double length, width, totalarea, totallength;
const double feet = 3.75;
//questions
Console.Title = "Double Glazing Window Calculator";
Console.WriteLine("Double Glazing Calculator\n");
bool InputFalse = false;
do
{
try
{
do
{
Console.Write("Enter the height of the of the window in meteres ");
length = double.Parse(Console.ReadLine());
Console.Write("Enter the width of the of the window in meteres ");
width = double.Parse(Console.ReadLine());
} while (length < 1 || width < 1);
//maths
totalarea = length * width * 2;
totallength = (length * 2 + width * 2) * feet;
Console.WriteLine("The total area of the glass required in m^2 (to 2 decinmal places) is {0} ", totalarea.ToString("0.##"));
Console.WriteLine("the total length of the wood required in feet (to 2 decimal places) is {0}", totallength.ToString("0.##"));
}
catch
{
InputFalse = (true);
Console.WriteLine("Enter a valid input (between 1 and 2^53)");
}
} while (true);