回复 1# wggfcusmq 的帖子
using System;
namespace ConApp3
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class InputDoubles
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
double dBase = GetDouble("Enter the base: ");
double dExp = GetDouble("Enter the exponent: ");
Console.WriteLine("{0} th the power of {1} is {2}",
dBase,dExp,Math.Pow(dBase,dExp));
}
static double GetDouble(string strPrompt)
{
double dValue = Double.NaN;
do
{
Console.Write(strPrompt);
try
{
dValue = Double.Parse(Console.ReadLine());
}
catch (System.Exception e)
{
Console.WriteLine();
Console.WriteLine("You typed an invaild number!");
Console.WriteLine("Please try again.");
Console.WriteLine();
}
} while (Double.IsNaN(dValue));
return dValue;
}
}
}