第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 C# 中的 if-else 語句中插入一個循環(huán)?

如何在 C# 中的 if-else 語句中插入一個循環(huán)?

C#
慕運維8079593 2022-12-24 10:58:33
我正在嘗試完成我的一種作業(yè),它應(yīng)該要求一個十進制數(shù)。如果用 . 而不是 ,文本“你需要按照瑞典標準用 (,) 寫你的十進制數(shù)”。這里我希望程序循環(huán)返回,因此用戶必須重試,直到用 (,) 輸入十進制數(shù)。在此之后,程序?qū)⒃儐柲獙⑵渌纳嵛迦氲蕉嗌傥恍?shù)。但目前我的程序只是輸出你需要使用的文本,根據(jù)瑞典標準,后面跟著文本“你想將它四舍五入到多少小數(shù)”,如果錯誤則不循環(huán)第一個語句。我目前嘗試更改一些內(nèi)容,但通常會導致程序崩潰。我目前使用“else break;” 到地方和代碼未完成但功能。需要更多代碼來完成我的任務(wù),但目前卡在循環(huán)問題上static void Main(string[] args)        {            double value1;            int round1;            while (true)            {                Console.Write("Enter a decimal-number: ");                string StrValue = Console.ReadLine();                bool success = Double.TryParse(StrValue, out value1);                if (!success)                {                    Console.WriteLine("You need to use (,) as decimal-sign according to Swedish standard!"); //From here I want a loop if . is used instead of ,                }                Console.Write("With how many decimal-numbers do you want to round it down to?: ");                string StrRound = Console.ReadLine();                bool success1 = Int32.TryParse(StrRound, out round1);                if (!success1)                {                    Console.WriteLine("Only use whole numbers when rounding");                }                else break;            }        }    }}我希望程序在第一個語句之后循環(huán),但我不知道為什么它沒有以及我應(yīng)該如何解決這個問題!
查看完整描述

1 回答

?
九州編程

TA貢獻1785條經(jīng)驗 獲得超4個贊

用 while 循環(huán)替換 if 條件,試試這個:


static void Main(string[] args)

    {

        double value1;

        int round1;


        while (true)

        {

            Console.Write("Enter a decimal-number: ");

            string StrValue = Console.ReadLine();


            bool success = Double.TryParse(StrValue, out value1);

            while (!success)

            {

                 Console.WriteLine("You need to use (,) as decimal-sign according to Swedish standard!"); //From here I want a loop if . is used instead of ,

                 StrValue = Console.ReadLine();

                 success = Double.TryParse(StrValue, out value1);

            }


            Console.Write("With how many decimal-numbers do you want to round it down to?: ");

            string StrRound = Console.ReadLine();


            bool success1 = Int32.TryParse(StrRound, out round1);

            if (!success1)

            {

                Console.WriteLine("Only use whole numbers when rounding");

            }

            else break;

        }

    }


}


查看完整回答
反對 回復(fù) 2022-12-24
  • 1 回答
  • 0 關(guān)注
  • 108 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號