方法 'Main_Calculations' 没有重载需要 2 个参数
No overload for method 'Main_Calculations' takes 2 arguments
static void Main(字符串[] args)
{
int choice;
choice = 0;
double length;
length = 0.00;
double height;
height = 0.00; //initiating variables
double base1;
base1 = 0.00;
double width;
width = 0.00;
double radius;
radius = 0.00;
double total;
total = 0.00;
Console.WriteLine("What shape would you like to make?");
Console.WriteLine("Please select one option (1, 2, 3, or 4)");
Console.WriteLine("1. Square.");
Console.WriteLine("2. Triangle."); //menu on the console
Console.WriteLine("3. Rectangle.");
Console.WriteLine("4. Circle.");
choice = int.Parse(Console.ReadLine());
if (choice == 1)
{
Console.WriteLine("Great! You chose Square.");
Console.WriteLine("Let's help you calculate the area of a square.");
Console.WriteLine("But first, we need to know the length of this square");
Console.WriteLine("Enter the length(Integer, or Decimal value is just fine:");
length = double.Parse(Console.ReadLine());
}
else if (choice == 2)
{
Console.WriteLine("Great! You chose Triangle.");
Console.WriteLine("Let's help you calculate the area of a triangle.");
Console.WriteLine("But first, we need to know the base and height of this triangle.");
Console.WriteLine("Enter the base(Integer, or Decimal value is just fine):");
base1 = double.Parse(Console.ReadLine()); //writing to the console depending on what choice
Console.WriteLine("Enter the height(Integer, or Decimal value is just fine):");
height = double.Parse(Console.ReadLine());
}
else if (choice == 3)
{
Console.WriteLine("Great! You chose Rectangle.");
Console.WriteLine("Let's help you calculate the area of a rectangle.");
Console.WriteLine("But first, we need to know the width and height of this rectangle.");
Console.WriteLine("Enter the width(Integer, or Decimal value is just fine):");
width = double.Parse(Console.ReadLine());
Console.WriteLine("Enter the height(Integer, or Decimal value is just fine):");
height = double.Parse(Console.ReadLine());
}
else if (choice == 4)
{
Console.WriteLine("Great! You chose Circle.");
Console.WriteLine("Let's help you calculate the area of a circle.");
Console.WriteLine("But first, we need to know the radius of this circle.");
Console.WriteLine("Enter the radius(Integer, or Decimal value is just fine:");
radius = double.Parse(Console.ReadLine());
}
Main_Calculations(args, total, base1, height, width, choice); //Sending Paramters to the next method
}
static void Main_Calculations(string[] args, double base1, double height, double width, double total, int choice) //bringing in parameters
{
if(choice == 2)
{
total = (base1 * height) * 0.5; //Calculations for triangle
Console.WriteLine("The area of a triangle is: " + total);
}
else if(choice == 3)
{
total = width * height; //calculations for rectangle
Console.WriteLine("The area of a rectangle is: " + total);
}
Main_Calculations(choice, total); //Sending Paramters to the next method
}
static void Main_Calculations(double length, double radius, double total, double choice)
{
if(choice == 1)
{
total = length * length; //Calculations for square
Console.WriteLine("The area of a square is: " + total);
}
else if(choice == 4)
{
total = (radius * radius) * 3.14; //calculations for circle
Console.WriteLine("The area of a circle is " + total); //prints the answer to the console
}
}
}
}
我的 (Math_Calculations) 的第二个发件人给我一个错误,因为没有重载需要 2 个参数,我不明白为什么它不能像我所拥有的那样工作。看来我可能只是遗漏了一个短语,我已经进入和退出代码,希望现在有用。
用行号回答会更容易,但你打电话给
Main_Calculations(选择,总计);
当没有像 Habib 指出的那样需要两个 arguments.Just 的 Main_Calculations 方法时。
当你调用第二个方法时Math_Calculations,当你在方法中要求4个参数时,你只给方法2个参数
所以,你需要做的是,或者你给 2dn Math_Calculations 调用额外的 2 个参数,或者你从方法中删除 2 个参数。
static void Main(字符串[] args) {
int choice;
choice = 0;
double length;
length = 0.00;
double height;
height = 0.00; //initiating variables
double base1;
base1 = 0.00;
double width;
width = 0.00;
double radius;
radius = 0.00;
double total;
total = 0.00;
Console.WriteLine("What shape would you like to make?");
Console.WriteLine("Please select one option (1, 2, 3, or 4)");
Console.WriteLine("1. Square.");
Console.WriteLine("2. Triangle."); //menu on the console
Console.WriteLine("3. Rectangle.");
Console.WriteLine("4. Circle.");
choice = int.Parse(Console.ReadLine());
if (choice == 1)
{
Console.WriteLine("Great! You chose Square.");
Console.WriteLine("Let's help you calculate the area of a square.");
Console.WriteLine("But first, we need to know the length of this square");
Console.WriteLine("Enter the length(Integer, or Decimal value is just fine:");
length = double.Parse(Console.ReadLine());
}
else if (choice == 2)
{
Console.WriteLine("Great! You chose Triangle.");
Console.WriteLine("Let's help you calculate the area of a triangle.");
Console.WriteLine("But first, we need to know the base and height of this triangle.");
Console.WriteLine("Enter the base(Integer, or Decimal value is just fine):");
base1 = double.Parse(Console.ReadLine()); //writing to the console depending on what choice
Console.WriteLine("Enter the height(Integer, or Decimal value is just fine):");
height = double.Parse(Console.ReadLine());
}
else if (choice == 3)
{
Console.WriteLine("Great! You chose Rectangle.");
Console.WriteLine("Let's help you calculate the area of a rectangle.");
Console.WriteLine("But first, we need to know the width and height of this rectangle.");
Console.WriteLine("Enter the width(Integer, or Decimal value is just fine):");
width = double.Parse(Console.ReadLine());
Console.WriteLine("Enter the height(Integer, or Decimal value is just fine):");
height = double.Parse(Console.ReadLine());
}
else if (choice == 4)
{
Console.WriteLine("Great! You chose Circle.");
Console.WriteLine("Let's help you calculate the area of a circle.");
Console.WriteLine("But first, we need to know the radius of this circle.");
Console.WriteLine("Enter the radius(Integer, or Decimal value is just fine:");
radius = double.Parse(Console.ReadLine());
}
Main_Calculations(args, total, base1, height, width, choice); //Sending Paramters to the next method
}
static void Main_Calculations(string[] args, double base1, double height, double width, double total, int choice) //bringing in parameters
{
if(choice == 2)
{
total = (base1 * height) * 0.5; //Calculations for triangle
Console.WriteLine("The area of a triangle is: " + total);
}
else if(choice == 3)
{
total = width * height; //calculations for rectangle
Console.WriteLine("The area of a rectangle is: " + total);
}
Main_Calculations(choice, total); //Sending Paramters to the next method
}
static void Main_Calculations(double length, double radius, double total, double choice)
{
if(choice == 1)
{
total = length * length; //Calculations for square
Console.WriteLine("The area of a square is: " + total);
}
else if(choice == 4)
{
total = (radius * radius) * 3.14; //calculations for circle
Console.WriteLine("The area of a circle is " + total); //prints the answer to the console
}
}
}
}
我的 (Math_Calculations) 的第二个发件人给我一个错误,因为没有重载需要 2 个参数,我不明白为什么它不能像我所拥有的那样工作。看来我可能只是遗漏了一个短语,我已经进入和退出代码,希望现在有用。
用行号回答会更容易,但你打电话给
Main_Calculations(选择,总计);
当没有像 Habib 指出的那样需要两个 arguments.Just 的 Main_Calculations 方法时。
当你调用第二个方法时Math_Calculations,当你在方法中要求4个参数时,你只给方法2个参数 所以,你需要做的是,或者你给 2dn Math_Calculations 调用额外的 2 个参数,或者你从方法中删除 2 个参数。