Option yes/no C# Console

后端 未结 6 1356
暗喜
暗喜 2021-01-15 01:15

I\'m creating a C# program for the Currency Converter by console. At the end I would to insert \"Continue? (yes/no)\". Here the user have to chose. I\'ve tried this but it

6条回答
  •  别那么骄傲
    2021-01-15 01:37

    This should fix your problem: And you should make your variable "risposta" ToLower so that it doesnt matter if you type a small or big letter (y or Y)

    float Dollaro = 1.32f, Euro;
                float Cambio;
                string EuroStr;
    
                string risposta = "Y";
    
                do
                {
                    Console.Write("Euro: ");
                    EuroStr = Console.ReadLine();
                    Euro = float.Parse(EuroStr);
    
                    Cambio = Dollaro * Euro;
    
                    Console.WriteLine("Dollaro: " + Cambio);
                    Console.WriteLine("Vuoi continuare? (yes/no)");
                    risposta = Console.ReadLine();
    
                    if (risposta.Equals("Y"))
                    {
                        Console.WriteLine("Yes");
                    }
                    else if (risposta.Equals("N"))
                    {
                        Console.WriteLine("No");
                    }
    
                } while (risposta.ToLower() == "y");
    

提交回复
热议问题