从用户输入的数据将字符转换为大写

时间:2014-03-14 04:00:13

标签: c# char uppercase toupper

我正在尝试为酒店创建一个程序,用户要在其中输入一个字符(S,D或L),并且该字符应该与下一行的代码相对应。我需要帮助转换用户输入(无论他们输入什么方式)转换为大写,然后我可以使用if语句来做我需要做的事情。 到目前为止,我的代码如下:

public static void Main()
{
    int numdays;
    double total = 0.0;
    char roomtype, Continue;

    Console.WriteLine("Welcome to checkout. We hope you enjoyed your stay!");

    do
    {
        Console.Write("Please enter the number of days you stayed: ");
        numdays = Convert.ToInt32(Console.ReadLine());

        Console.WriteLine("S = Single, D = Double, L = Luxery");
        Console.Write("Please enter the type of room you stayed in: ");
        roomtype = Convert.ToChar(Console.ReadLine());


     **^Right Her is Where I Want To Convert To Uppercase^**

        total = RoomCharge(numdays,roomtype);
        Console.WriteLine("Thank you for staying at our motel. Your total is: {0}", total);

        Console.Write("Do you want to process another payment? Y/N? : ");
        Continue = Convert.ToChar(Console.ReadLine());


    } while (Continue != 'N');

    Console.WriteLine("Press any key to end");
    Console.ReadKey();
}

public static double RoomCharge(int NumDays, char RoomType)
{
    double Charge = 0;

    if (RoomType =='S')
        Charge = NumDays * 80.00;

    if (RoomType =='D')
        Charge= NumDays * 125.00;

    if (RoomType =='L')
        Charge = NumDays * 160.00;

    Charge = Charge * (double)NumDays;
    Charge = Charge * 1.13;

    return Charge;
} 

3 个答案:

答案 0 :(得分:10)

尝试使用默认的ToUpper方法。

roomtype = Char.ToUpper(roomtype);

完成此http://msdn.microsoft.com/en-us/library/7d723h14%28v=vs.110%29.aspx

答案 1 :(得分:2)

roomtype = Char.ToUpper(roomtype);

答案 2 :(得分:0)

public static void Main()
{
int numdays;
double total = 0.0;
char roomtype, Continue;

Console.WriteLine("Welcome to checkout. We hope you enjoyed your stay!");

do
{
    Console.Write("Please enter the number of days you stayed: ");
    numdays = Convert.ToInt32(Console.ReadLine());

    Console.WriteLine("S = Single, D = Double, L = Luxery");
    Console.Write("Please enter the type of room you stayed in: ");
    roomtype = Convert.ToChar(Console.ReadLine());
    roomtype = Char.ToUpper(roomtype);   

    total = RoomCharge(numdays,roomtype);
    Console.WriteLine("Thank you for staying at our motel. Your total is: {0}", total);

    Console.Write("Do you want to process another payment? Y/N? : ");
    Continue = Convert.ToChar(Console.ReadLine());


} while (Continue != 'N');

Console.WriteLine("Press any key to end");
Console.ReadKey();
}