/* 你好我是一名学生,试图做一些练习编程任务,但我似乎无法让我的一个变量在函数中工作,我需要用户输入变量的值,但它想要我们在 PowerOf 函数而不是 Main 函数中声明它,很抱歉成为 n00b,但任何帮助将不胜感激。[:*/
using System;
namespace ThePowerOf
{
class MainClass
{
public static void Main (string[] args)
{
string sUserInput;
int iUserNum1 = 0;
int iUserNum2 = 0;
int iPower = 0;
Console.WriteLine ("Enter a number");
sUserInput = Console.ReadLine();
iUserNum1 = Int16.Parse(sUserInput);
Console.WriteLine ("Enter a number");
sUserInput = Console.ReadLine();
iUserNum2 = Int16.Parse(sUserInput);
iPower = PowerOf(iUserNum1);
Console.WriteLine((iUserNum1) + (" To the power of ") + (iUserNum2) + (" = ") + (iPower));
Console.ReadLine();
}
static int PowerOf(int iUserNum1)
{
for (int i = 0; i < iUserNum2; ++i)
{
iUserNum1 = (iUserNum1 * iUserNum1);
}
return iUserNum1;
}
}
}