我已经尽力了,只是没有输出养老金领取者的打折信息,输入y时,费用位于标记为Pensionerdiscount的程序的底部。任何帮助,将不胜感激,谢谢。

   const int MaxRooms = 5; // max size of array needed
        double[] roomCosts = new double[MaxRooms];
        string pensioner; // Pensioner discount ? y for yes, n for no
        int nRooms;
        double area, mCost, lCost; // area, materials and labour costs
        int i;
        string customer;
        double totalCost = 0.0;
        double totallabour = 0.0; // calculated seperately to allow discount
        const double setupCost = 30.00; // setup cost/room
        double pensionerDiscountRate = 0.1; // 10% discount for pensioner
        double discount, discountedTotal;
        double[] basePrices = {0, 4.0, 8.0, 12.0 };
        int jobType; // used to index basePrices
        // prices per sq metre for paint only, paint+prep, prep+paper+paint
        Console.Write("enter name of customer: ");
        customer = Console.ReadLine();
        Console.Write("\nenter number of rooms to quote for: ");
        nRooms = Convert.ToInt32(Console.ReadLine());
        Console.Write("\nPensioner discount (y/n) ? ");
        pensioner = Console.ReadLine().ToUpper();
        Console.WriteLine();
        for (i = 0; i < nRooms; i++)
        {
            Console.Write("enter area for room {0}: ", i + 1);
            area = Convert.ToDouble(Console.ReadLine());
            Console.Write("enter job type for room {0} " +
                "(1 - paint only, 2 paint+prep, 3 paint,prep+paper ", i + 1);
            jobType = Convert.ToInt32(Console.ReadLine());

            int newVariable = jobType + 1;
            lCost = area * basePrices[newVariable] + setupCost; // labour cost
            totallabour += lCost; // total labour cost separately

            Console.Write("\nenter materials cost for room {0}: ", i + 1);
            mCost = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine();
            roomCosts[i] = lCost + mCost; // store labour and material costs for room
            totalCost += roomCosts[i];
        }

        // main report heading
        Console.WriteLine("Decorators R US Job Quotation");
        Console.WriteLine("=============================");
        Console.WriteLine();
        Console.WriteLine("\nName of customer: {0}\n", customer);
        Console.WriteLine();
        Console.WriteLine("No. of rooms: {0}", nRooms);

        // output subheadings
        Console.WriteLine("Room\tCost\t%of Total");

        for (i = 0; i > nRooms; i++)
        {
            Console.Write("{0}\t", i + 1);
            Console.Write("£{0:0.00}\t", roomCosts[i]);
            Console.WriteLine("{0:00.0}%", roomCosts[i] * 100 / totalCost);
        }

        Console.WriteLine("Total Cost £{0:0.00}", totalCost);

        if (pensioner == "y")
        {
           // deduct pensioner discount based on 10% of labour cost
            discount = totallabour * pensionerDiscountRate;
            discountedTotal = totalCost - discount;
            Console.WriteLine("Pensioner Discount - £{0:0.00}", discount);

            Console.WriteLine("Discounted Cost £{0:0.00}", discountedTotal);
            Console.WriteLine();

        }



        Console.WriteLine("press enter to continue");
        Console.ReadLine();

    }
}


}

最佳答案

您正在使用ToUpper()获得折扣(y / n):

Console.Write("\nPensioner discount (y/n) ? ");
pensioner = Console.ReadLine().ToUpper();  // USING ToUpper()


但是稍后检查if (pensioner == "y")是小写的。

使用:

pensioner = Console.ReadLine().ToLower();


或将其保留为ToUpper()并检查:

if (pensioner == "Y")

关于c# - 剩余的程序未输出,即折扣信息,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8918153/

10-13 06:06