C#提示计算器,方法不调用,没有错误信息

时间:2015-09-13 11:28:05

标签: c#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TipCalculator
{

class Program
{

    static void Main(string[] args)
    {
        string answer;
        float totalPrice;
        Console.WriteLine("Would you like to calculate a tip?");
        answer = Console.ReadLine();
        if (answer == "yes")
        {
            Console.WriteLine("Please enter the total price of your meal");
            totalPrice = float.Parse(Console.ReadLine());

            if (totalPrice >= 20.00)
                TipCalculator.over20(totalPrice);
            else if (totalPrice < 20)
                TipCalculator.under20(totalPrice);
            else Console.WriteLine("Error. Please type in the value of the bill again");

        }
        else if (answer == "no")
            Console.WriteLine("Please run this again when you wish to calculate a tip.");
        else
            Console.WriteLine("Error. Please type in \"yes\" or \"no\"");

        Console.ReadLine();
    }

}
public class TipCalculator
{
    public static string over20(float bill)

    {
      float tip, totalBill;
      tip = (bill * (float)1.2);
      totalBill = (tip + bill);
      return "Very good. The total tip to be paid is " + tip + " and this will cost " + totalBill + "in total.";

    }

    public static string under20(float bill)
    {
        float tip, totalBill;
        tip = (bill * (float)1.1);
        totalBill = (tip + bill);
        return "Very good. The total tip to be paid is " + tip + " and this will cost " + totalBill + "in total.";

    }
}
}

当我尝试运行此代码时,不会显示错误,但以“非常好”开头的消息不会显示在over20或under20消息中。提前谢谢!

0 个答案:

没有答案