Converting Char to Uppercase From User Inputted Data
Asked Answered
W

3

6

I am trying to create a program for a hotel where the user is to enter a character (either S, D, or L) and that is supposed to correspond with a code further down the line. I need help converting the user input (no matter what way they enter it) to be converted to uppercase so I can then use an if statement to do what I need to do. My code so far is the following:

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;
} 
Wean answered 14/3, 2014 at 4:0 Comment(4)
The String class has an overloaded method to compare text in case insensitive mode but I'm not sure if it exists for Char, I don't have an IDE handy right now. So I would suggest you use a string variable for roomtype.Rhizomorphous
what language is it? c++?Forcible
Why not rather make use of the string type, rather than char?Arrant
Use .ToUpper(); This can do the task.Carillo
C
11

Try default ToUpper method.

roomtype = Char.ToUpper(roomtype);

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

Cortezcortical answered 14/3, 2014 at 4:51 Comment(0)
I
3
roomtype = Char.ToUpper(roomtype);
Inartificial answered 14/3, 2014 at 4:12 Comment(0)
I
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();
}
Impermissible answered 14/3, 2014 at 4:42 Comment(2)
Thanks a million! I can't believe how simple of a mistake I made! I wrote:Wean
char.ToUpper(roomtype); instead of: roomtype = char.ToUpper(roomtype);Wean

© 2022 - 2024 — McMap. All rights reserved.