Option yes/no C# Console

后端 未结 6 1399
暗喜
暗喜 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:34

    You should move code where you do operation to do while loop.

    Try this:

        static void Main(string[] args)
        {
            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 == "Y");
        }
    

提交回复
热议问题