If statement 我怎样才能解决这个问题?我在节目中解释

If statement 我怎样才能解决这个问题?我在节目中解释,if-statement,compiler-errors,switch-statement,If Statement,Compiler Errors,Switch Statement,//我在程序中犯了3个错误。我希望我所有的错误都能在最后显示出来。所以,如果有任何错误,程序显示错误并关闭控制台,否则,将进行计算 class Program { static void Main(string[] args) { string name; string color; string shipping; string error;

//我在程序中犯了3个错误。我希望我所有的错误都能在最后显示出来。所以,如果有任何错误,程序显示错误并关闭控制台,否则,将进行计算

 class Program
    {
        static void Main(string[] args)
        {
            string name;
            string color;
            string shipping;
            string error;

            int shirtCost;
            int shippingCost;
            int quantity;

            Console.WriteLine("---------------------------------------------");
            Console.WriteLine("  Welcome to Conestoga Online Shirts store");
            Console.WriteLine("---------------------------------------------");

            Console.WriteLine(" Please add your name:" + Environment.NewLine);
            name = Console.ReadLine();

            Console.WriteLine(Environment.NewLine + "What colour would you like to buy " + name + "?" + Environment.NewLine);
            Console.WriteLine("--------------------------------------------------------------------------------");
            Console.WriteLine("Green = $20, Blue = $20, Yellow = $10, Brown = $5, Other = $15" + Environment.NewLine);
            Console.WriteLine("--------------------------------------------------------------------------------" + Environment.NewLine);
            color = Console.ReadLine();

            switch (color)
            {
                case "green":
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine(Environment.NewLine + "Your color is Green" + Environment.NewLine);
                    shirtCost = 20;
                    break;
                case "blue":
                    Console.ForegroundColor = ConsoleColor.Blue;
                    Console.WriteLine(Environment.NewLine + "Your color is Blue" + Environment.NewLine);
                    shirtCost = 20;
                    break;
                case "yellow":
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine(Environment.NewLine + "Your color is Yellow" + Environment.NewLine);
                    shirtCost = 10;
                    break;
                case "brown":
                    Console.ForegroundColor = ConsoleColor.Gray;
                    Console.WriteLine(Environment.NewLine + "Your color is Brown" + Environment.NewLine);
                    shirtCost = 5;
                    break;
                case "other":
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine(Environment.NewLine + "Your color is Other" + Environment.NewLine);
                    shirtCost = 15;
                    break;
                 default:
                    Console.ForegroundColor = ConsoleColor.Red;
                    error = "Error: Choose the right color.";  //i want this error show up at the end
                    break;
            }
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.WriteLine(Environment.NewLine + "How many would you like to order?" + Environment.NewLine);
            Console.WriteLine("!!!!!!!Notic: Customer cane choose Between 1 to 200!!!!!!!" + Environment.NewLine);
            quantity = int.Parse(Console.ReadLine());

            if ((quantity >= 1) && (quantity <= 200))
            {
                Console.WriteLine(Environment.NewLine + "Your quantity is " + quantity + Environment.NewLine);
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                error = "Error: Choose the right Number."; //i want this error show up at the end
            }

            Console.ForegroundColor = ConsoleColor.Gray;
            Console.WriteLine("What kind of shipping method you want to choose?" + Environment.NewLine);
            Console.WriteLine("-----------------------------------------------------------------------");
            Console.WriteLine("Expedited = $10, Standard = $5, None = $0");
            Console.WriteLine("-----------------------------------------------------------------------" + Environment.NewLine);
            shipping = Console.ReadLine();

            switch (shipping)
            {
                case "expedited":
                    Console.WriteLine("Youe shipping is Expedited");
                    shippingCost = 10;
                    break;
                case "standard":
                    Console.WriteLine("Youe shipping is Standard");
                    shippingCost = 5;
                    break;
                case "none":
                    Console.WriteLine("Youe shipping is None");
                    shippingCost = 0;
                    break;
                default:
                    Console.ForegroundColor = ConsoleColor.Red;
                    error = "Error: Choose the right shipping method.";//i want this error show up at the end
                    break;
            }

            Console.ForegroundColor = ConsoleColor.Gray;

// i want my error show up here. so if there are any error. show up the error and than close the console, but if there are not any error, will do the math.


        }
    }
}
类程序
{
静态void Main(字符串[]参数)
{
字符串名;
字符串颜色;
字符串装运;
字符串错误;
国际衬衫成本;
国际运输成本;
整数;
Console.WriteLine(“-------------------------------------------------------------”;
Console.WriteLine(“欢迎来到康内斯托加在线衬衫店”);
Console.WriteLine(“-------------------------------------------------------------”;
Console.WriteLine(“请添加您的姓名:“+Environment.NewLine”);
name=Console.ReadLine();
Console.WriteLine(Environment.NewLine+“您想买什么颜色”+name+“?”+Environment.NewLine);
Console.WriteLine(“------------------------------------------------------------------------------------------------”;
WriteLine(“绿色=20美元,蓝色=20美元,黄色=10美元,棕色=5美元,其他=15美元+环境.换行符);
Console.WriteLine(“--------------------------------------------------------------------------------------”+Environment.NewLine);
color=Console.ReadLine();
开关(彩色)
{
案例“绿色”:
Console.ForegroundColor=ConsoleColor.Green;
Console.WriteLine(Environment.NewLine+“您的颜色是绿色”+Environment.NewLine);
衬衫成本=20;
打破
案例“蓝色”:
Console.ForegroundColor=ConsoleColor.Blue;
Console.WriteLine(Environment.NewLine+“您的颜色是蓝色”+Environment.NewLine);
衬衫成本=20;
打破
案例“黄色”:
Console.ForegroundColor=ConsoleColor.Yellow;
Console.WriteLine(Environment.NewLine+“您的颜色是黄色”+Environment.NewLine);
衬衫成本=10;
打破
案例“布朗”:
Console.ForegroundColor=ConsoleColor.Gray;
Console.WriteLine(Environment.NewLine+“您的颜色是棕色”+Environment.NewLine);
衬衫成本=5;
打破
案例“其他”:
Console.ForegroundColor=ConsoleColor.White;
Console.WriteLine(Environment.NewLine+“您的颜色是其他的”+Environment.NewLine);
衬衫成本=15;
打破
违约:
Console.ForegroundColor=ConsoleColor.Red;
error=“error:选择正确的颜色。”;//我希望在结尾显示此错误
打破
}
Console.ForegroundColor=ConsoleColor.Gray;
Console.WriteLine(Environment.NewLine+“您要订购多少?”+Environment.NewLine);
Console.WriteLine(“!!!!!!!!!注意:客户可以选择1到200!!!!!!!”+Environment.NewLine);
quantity=int.Parse(Console.ReadLine());

如果((数量>=1)和&(数量如果您声明字符串错误,最好使用:
string error=”“
; 然后在您的情况下:
error=“My error!”;

并写下:

Console.WriteLine(error);
Console.ReadLine(); //wait for input from keyboard.