【发布时间】:2015-12-23 13:59:34
【问题描述】:
我试图让 newA 和 newC 脱离该方法,但它给了我这个错误。如果数字从方法中出来,我也不知道如何分开,请帮忙,我还是个新手:( 到目前为止,代码从用户那里获得了 3 个数字。然后我将它们放入方法中,我需要取出 newA 和 newC 并将它们存储在单独的变量中。
namespace factorising_quadratic_expressions
{
class Program
{
static void Main(string[] args)
{
int divideBy = 0;
Console.WriteLine("The form is ax^2 + bx + c"); // all of this is part of my working out.
Console.WriteLine("Write down a ");
int a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Write down b ");
int b = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Write down c ");
int c = Convert.ToInt32(Console.ReadLine());
int num = a * c;
g(num, b, divideBy); // i need to make 2 variables with newA and newC here
}
public static int g(int num01, int num02, int num03)
{
int x = 0;
while (x == 0)
{
if (num03 > 20)
{
Console.WriteLine("this is not possible to factorise");
x = x + 1;
}
num03 = num03 + 1;
int newA = num01 / num03; //calculations done to get newC and newA
int newC = num03;
if (newA + newC == num02)
{
x = x + 1;
}
else if (newA - newC == num02)
{
x = x + 1;
}
else if (newC - newA == num02)
{
x = x + 1;
}
num01 = newC; //me failing at trying to return them back
num03 = newA;
return num01; return num02; return num03;
}
}
}
}
【问题讨论】:
标签: methods return return-value