小编use*_*316的帖子

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

我正在尝试为酒店创建一个程序,用户输入一个字符(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 …
Run Code Online (Sandbox Code Playgroud)

c# char uppercase toupper

5
推荐指数
2
解决办法
2万
查看次数

试图弄清楚数组是否已排序

我试图找出用户输入的数组是否已排序(尽管不尝试排序).如果用户的输入是从最小到最大的升序,我想写一条消息说"输入已排序",如果不是"用户输入未排序".

到目前为止这是我的代码:

public static void Main()
{
    int[] array = new int[20];
    int n = 0;
    char Continue;

    InputArray(array, ref n);
    IsSorted(array, n);

    Console.WriteLine("{0}", IsSorted(array, n));

    do{


        Console.Write("Would you like to continue? Y/N : ");
        Continue = Convert.ToChar(Console.ReadLine());
        Continue = char.ToUpper(Continue);

      }while(Continue != 'N');

}

    public static void InputArray(int[] array, ref int n)
{
    int i = 0;

    Console.Write("Enter a number of elements under 20: ");
    n = Convert.ToInt32(Console.ReadLine());

    if (n < 0 || n > 20)
    {
        Console.Write("Please enter …
Run Code Online (Sandbox Code Playgroud)

c# arrays sorting

0
推荐指数
1
解决办法
78
查看次数

标签 统计

c# ×2

arrays ×1

char ×1

sorting ×1

toupper ×1

uppercase ×1