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

本文关键字:转换 数据 字符 用户 输入 | 更新日期: 2023-09-27 17:50:23

我试图为用户输入字符(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;
} 

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

尝试默认的ToUpper方法

roomtype = Char.ToUpper(roomtype);

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

roomtype = Char.ToUpper(roomtype);
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();
}