2014-03-14 3 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 클래스를 통해

roomtype = Char.ToUpper(roomtype); 

이동은 대소 문자를 구분 모드에서 텍스트를 비교하는 오버로드 된 방법을 가지고 있지만 나는 그것이 숯불이있는 경우 잘 모르겠어요, 지금은 IDE를 편리이없는 . 그래서 roomtype에 문자열 변수를 사용하는 것이 좋습니다. – Raj

+0

어떤 언어입니까? C++? – brokenfoot

+0

'char'보다는'string' 유형을 사용하는 것이 좋을까요? –

답변

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

관련 문제