2014-03-14 36 views
3

我想创建一个酒店的用户输入一个字符(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; 
} 
+1

String类有一个重载的方法在不区分大小写模式比较文本,但我不知道它是否存在字符,我没有一个IDE方便,现在。所以我建议你为roomtype使用一个字符串变量。 – Raj

+0

它是什么语言? C++? – brokenfoot

+0

为什么不使用'string'类型而不是'char'? –

回答

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

非常感谢!我无法相信我犯了多么简单的错误!我写道: – user3418316

+0

char.ToUpper(roomtype);而不是:roomtype = char.ToUpper(roomtype); – user3418316

相关问题