コード例 #1
0
        static void Main(string[] args)
        {
            ShippedOrder[] orders = new ShippedOrder[5];
            int orderNum;
            string customerName;
            int qty;
            bool reenter = false;

            for (int i = 0; i < orders.Length; i++) {//counting loop, fills the orders array

                orderNum = Input.promptInt32(reenter ? "Please reenter: " : "Enter order number: ",
                    "Please enter a valid order number... ");

                reenter = false;

                foreach (ShippedOrder value in orders) {//validate there are no repeat orders
                    if (value != null && orderNum == value.OrderNum) {
                        Console.WriteLine("Sorry, the order number {0} is a duplicate... ", orderNum);
                        reenter = true;
                    }
                }

                if (reenter == true) {//repeat the current iteration if need to reenter data
                    i--;
                    continue;
                }

                customerName = Input.promptString("Enter customer name: ",
                    "Please enter something into the prompt... ");
                qty = Input.promptInt32("Enter quantity: ", "Please enter a valid quantity... ");

                //instantiate the non-existant object
                orders[i] = new ShippedOrder(orderNum, customerName, qty);

                //put a line between inputs for better readability
                Console.WriteLine();

            }//end outer loop

            Console.WriteLine();

            Array.Sort(orders);

            Console.WriteLine("Summary: ");
            double total = 0;

            foreach (ShippedOrder value in orders) {//print out each member of the array
                Console.WriteLine(value.ToString());
                total += value.TotalPrice;
            }

            Console.WriteLine();
            Console.WriteLine("Total for all orders is {0:C}", total);
            pause();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            ShippedOrder[] orders = new ShippedOrder[5];
            int            orderNum;
            string         customerName;
            int            qty;
            bool           reenter = false;

            for (int i = 0; i < orders.Length; i++)  //counting loop, fills the orders array

            {
                orderNum = Input.promptInt32(reenter ? "Please reenter: " : "Enter order number: ",
                                             "Please enter a valid order number... ");

                reenter = false;

                foreach (ShippedOrder value in orders)  //validate there are no repeat orders
                {
                    if (value != null && orderNum == value.OrderNum)
                    {
                        Console.WriteLine("Sorry, the order number {0} is a duplicate... ", orderNum);
                        reenter = true;
                    }
                }

                if (reenter == true)  //repeat the current iteration if need to reenter data
                {
                    i--;
                    continue;
                }

                customerName = Input.promptString("Enter customer name: ",
                                                  "Please enter something into the prompt... ");
                qty = Input.promptInt32("Enter quantity: ", "Please enter a valid quantity... ");

                //instantiate the non-existant object
                orders[i] = new ShippedOrder(orderNum, customerName, qty);

                //put a line between inputs for better readability
                Console.WriteLine();
            }//end outer loop

            Console.WriteLine();


            Array.Sort(orders);


            Console.WriteLine("Summary: ");
            double total = 0;

            foreach (ShippedOrder value in orders)  //print out each member of the array
            {
                Console.WriteLine(value.ToString());
                total += value.TotalPrice;
            }

            Console.WriteLine();
            Console.WriteLine("Total for all orders is {0:C}", total);
            pause();
        }//end main