我想創建一個酒店的用戶輸入一個字符(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;
}
String類有一個重載的方法在不區分大小寫模式比較文本,但我不知道它是否存在字符,我沒有一個IDE方便,現在。所以我建議你爲roomtype使用一個字符串變量。 – Raj
它是什麼語言? C++? – brokenfoot
爲什麼不使用'string'類型而不是'char'? –