C# 计划在「;如果;语句和强制类别“;B";

C# 计划在「;如果;语句和强制类别“;B";,c#,C#,好的,所以这个程序在第一个“如果”语句中就一直崩溃,一直把我带到caragory B。有什么提示吗?失败在哪里?需要添加或删除哪些代码 using System; class Program { enum Numbers { standard = 1, express = 2, same = 3 }; const int A = 1, B = 2; const int Y = 3, N = 4; static void Main() {

好的,所以这个程序在第一个“如果”语句中就一直崩溃,一直把我带到caragory B。有什么提示吗?失败在哪里?需要添加或删除哪些代码

using System;

class Program
{
    enum Numbers { standard = 1, express = 2, same = 3 };

    const int A = 1, B = 2;
    const int Y = 3, N = 4;
    static void Main()
     {

        double cost, LB;
        int Number_of_items ;
        int myNumbers;
        char catagory = 'A';
        char surcharge = 'Y';

        Console.WriteLine("please enter the type of shiping you want");
        Console.WriteLine("Enter 1:standard shipping.");
        Console.WriteLine("Enter 2:express shipping.");
        Console.WriteLine("Enter 3:same day shipping.");

        myNumbers = int.Parse(Console.ReadLine());
        switch ((Numbers)myNumbers)
        { 
            case Numbers.standard:
                Console.WriteLine("thankyou for chooseing standerd shipping");
                Console.WriteLine("please choose a catagory");
                Console.Write("Type A or B to make your selection");
                catagory = char.Parse(Console.ReadLine());
                {      if (catagory==A)
                {
                    Console.Write("please enter the number of items");
                    Number_of_items = int.Parse(Console.ReadLine());
                    cost = 3 * Number_of_items;

                    Console.Write("is this shipment going to alaska or Hawaii? (Y or N)");
                    if (surcharge==Y)
                    {
                        cost = cost + 2.50;

                        Console.WriteLine("Total cost is {0}." , cost);
                    }
                    else 
                        Console.WriteLine("total cost is {0}." , cost);


                }
                else
                    Console.Write("please enter the weight in pounds");
               LB =  double.Parse(Console.ReadLine());
                cost = 1.45 * LB;
                Console.WriteLine("is this shipment going to alaska or Hawaii? (Y or N)");
        }
                if (surcharge==Y)
                {
                    cost = cost + 2.50;

                        Console.WriteLine("Total cost is {0}." , cost);
                }
                else 
                        Console.WriteLine("total cost is {0}." , cost);

                break;


                case Numbers.express:
                Console.WriteLine("thankyou for chooseing Express Shipping");
                Console.WriteLine("please choose a catagory");
                Console.Write("Type A or B to make your selection");
                catagory = char.Parse(Console.ReadLine());
                    {       if (catagory==A)
                        Console.Write("please enter the number of items");
                        Number_of_items = int.Parse(Console.ReadLine());
                        cost = 4 * Number_of_items;
                        {
                    Console.Write("is this shipment going to alaska or Hawaii? (Y or N)");
                    if (surcharge==Y)
                    {
                        cost = cost + 5.00;

                        Console.WriteLine("Total cost is {0}." , cost);
                    }
                    else 
                        Console.WriteLine("total cost is {0}." , cost);


                    }
                        if (surcharge==B)


                            Console.Write("please enter the weight in pounds");
               LB =  double.Parse(Console.ReadLine());
                cost = 2.50 * LB;
                Console.WriteLine("is this shipment going to alaska or Hawaii? (Y or N)");
                    }
                if (surcharge==Y)
                {
                    cost = cost + 5.00;

                        Console.WriteLine("Total cost is {0}." , cost);
                }
                else 
                        Console.WriteLine("total cost is {0}." , cost);
            break;





                case Numbers.same:
                Console.WriteLine("thankyou for chooseing Same Day Shipping");
                Console.WriteLine("please choose a catagory");
                Console.Write("Type A or B to make your selection");
                catagory = char.Parse(Console.ReadLine());
                if (catagory == A)
                    Console.Write("please enter the number of items");
                    Number_of_items = int.Parse(Console.ReadLine());
                    cost = 5.50 * Number_of_items;

                    Console.Write("is this shipment going to alaska or Hawaii? (Y or N)");
                    if (surcharge==Y)
                    {
                        cost = cost + 8.00;

                        Console.WriteLine("Total cost is {0}." , cost);
                    }
                    else 
                        Console.WriteLine("total cost is {0}." , cost);



                if (surcharge==B)

                    Console.Write("please enter the weight in pounds");
               LB =  double.Parse(Console.ReadLine());
                cost = 3.00 * LB;
                Console.WriteLine("is this shipment going to alaska or Hawaii? (Y or N)");

                if (surcharge==Y)
                {
                    cost = cost + 8.00;

                        Console.WriteLine("Total cost is {0}." , cost);
                }
                else 
                        Console.WriteLine("total cost is {0}." , cost);

                break;
        }
  Console.ReadLine();

    }//End Main()
}//End class Program

A是一个int变量,您为其赋值为1。 你可能想做: if(类别=='A') 不
如果(catagory==A)

如果我输入“A”,它仍然会将我带到“B”,这是一个非常长的方法。我建议你将它分解成简单的小方法,并使用单元测试来验证每个小方法的行为是否符合它们的要求。我已经分解了它,但它在所有3种情况下都在同一个位置失败了W,这有点难以理解。我认为在几个ifs之后,您缺少了一些大括号。您可能还想测试大写和小写字母(例如if((catagory='a')| |(catagory='a'))。此外,您没有在之前提示用户输入:if(overlay==Y),它也应该测试“Y”而不是“Y”。