Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > C# WinApp รบกวนช่วยตรวจสอบโค้ด ให้หน่อยครับ ต้องการให้ค่า x y เป็นจะนวนเต็ม ครับ



 

C# WinApp รบกวนช่วยตรวจสอบโค้ด ให้หน่อยครับ ต้องการให้ค่า x y เป็นจะนวนเต็ม ครับ

 



Topic : 137036



โพสกระทู้ ( 4,436 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook



โค้ด ครับ

Code (C#)
string intTostring(int i) {
            if (i == 1)
            {
                return "";
            }
            else if (i == -1)
            {
                return "-";
            }
            else { 
            return i.ToString();
            }
        
        }
        
        private string _Equation()
        {

            string s = "";
            int a = RandomNumberGenerator.GetInt32(1, 10);
            int x = RandomNumberGenerator.GetInt32(-5, 5);
            int b = RandomNumberGenerator.GetInt32(-10, 10);
            int y = RandomNumberGenerator.GetInt32(-5, 5);
            int d = RandomNumberGenerator.GetInt32(1, 3000);

            string o = (RandomNumberGenerator.GetInt32(1, 1000) > 500) ? "+" : "-";
            string ev = "";
            String _a ,_b,_c;
            
            _a = intTostring(a);
            _b = intTostring(b);
            switch (d)
            {
                case int n when (n >= 0 && n < 1000):
                    //ax+/-b=0
                    // ev = $"{a}{x} {o} {b}{y}  = 0";
                    do
                    {
                        a = RandomNumberGenerator.GetInt32(1, 10);
                        x = RandomNumberGenerator.GetInt32(-5, 5);
                        b = RandomNumberGenerator.GetInt32(-10, 10);
                        y = RandomNumberGenerator.GetInt32(-5, 5);

                        o = (RandomNumberGenerator.GetInt32(1, 1000) > 500) ? "+" : "-";
                    } while (a * x + (o == "+" ? b * y : -b * y) != 0);
                    _a = intTostring(a);
                    _b = intTostring(b);
                    ev = $"{_a}x {o} {_b}y  = 0";
                    break;

                case int n when (n >= 1000 && n < 2000):
                    //ax+/-b=c
                    ev = $"{_a}x {o} {_b}y  = {Eval.Execute<int>($"{a}{x} {o} {b}{y}")}";
                    break;

                case int n when (n >= 2000 && n <= 3000):
                    //ax = b+/-c
                    if (o == "+")
                        ev = $"{_a}x = {_b}y {o} {Eval.Execute<int>($"{a}{x} - {b}{y}")}";
                    else
                        ev = $"{_a}x = {_b}y {o} {Eval.Execute<int>($"{b}{y} - {a}{x}")}";
                    break;
            }

            // Parameter: Argument Position
  
            s = ev;




             a = RandomNumberGenerator.GetInt32(1, 10);
             b = RandomNumberGenerator.GetInt32(-10, 10);
             d = RandomNumberGenerator.GetInt32(1, 3000);

             o = (RandomNumberGenerator.GetInt32(1, 1000) > 500) ? "+" : "-";
            _a = intTostring(a);
            _b = intTostring(b);
            switch (d)
            {
                case int n when (n >= 0 && n < 1000):
                    //ax+/-b=0

                    do
                    {
                        a = RandomNumberGenerator.GetInt32(1, 10);
                        x = RandomNumberGenerator.GetInt32(-5, 5);
                        b = RandomNumberGenerator.GetInt32(-10, 10);
                        y = RandomNumberGenerator.GetInt32(-5, 5);

                        o = (RandomNumberGenerator.GetInt32(1, 1000) > 500) ? "+" : "-";
                    } while (a * x + (o == "+" ? b * y : -b * y) != 0);
                    _a = intTostring(a);
                    _b = intTostring(b);
                    ev = $"{_a}x {o} {_b}y  = 0";
                    break;

                case int n when (n >= 1000 && n < 2000):
                    //ax+/-b=c
                    ev = $"{_a}x {o} {_b}y  = {Eval.Execute<int>($"{a}{x} {o} {b}{y}")}";
                    break;

                case int n when (n >= 2000 && n <= 3000):
                    //ax = b+/-c
                    if (o == "+")
                        ev = $"{_a}x = {_b}y {o} {Eval.Execute<int>($"{a}{x} - {b}{y}")}";
                    else
                        ev = $"{_a}x =  {_b} y {o} {Eval.Execute<int>($"{b}{y} - {a}{x}")}";
                    break;
            }

            // Parameter: Argument Position
            return $"{s} and {ev}".Replace("--", "+").Replace("+-", "-").Replace("-+", "-")
                .Replace("- -", "+").Replace("+ -", "-").Replace("- +", "-");



        }


เหมือน ทดสอบแล้ว หลายๆ ค่าออกมาไม่ได้จำนวนเต็ม ครับ
6

36



Tag : .NET, Win (Windows App), C#







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2023-06-07 16:31:39 By : lamaka.tor View : 217 Reply : 3
 

 
ก่อนอื่นต้องรู้ว่าจะทำอะไรก่อน
ให้แก้สมการ หรือ สร้างสมการ หรือ เทียบสมการ หรืออื่นใด

หรือ เอาคำถามจาก ChatGPT มาด้วย
แต่ถ้าไม่สะดวก ตามที่ผมเคยบอก
AI ณ ปัจจุบัน ยังทำงานที่ซับซ้อนและปริมาณมากไม่ได้
และถ้าต้องการคำตอบที่แม่นยำกว่าเดิม
ควรถามมันเป็นภาษาอังกฤษ

แก้ที่ต้นเหตุง่ายกว่าปลายเหตุ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2023-06-07 21:02:11 By : 009
 


 

No. 2



โพสกระทู้ ( 4,436 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

ตอบความคิดเห็นที่ : 1 เขียนโดย : 009 เมื่อวันที่ 2023-06-07 21:02:11
รายละเอียดของการตอบ ::
ผมจะสร้างโจทย์สมการครับ
โดย เงื่อนไข คือ
ในการสุ่ม a b c x y จะต้องได้ค่า จำนวนเต็ม

Code (C#)
            int a = RandomNumberGenerator.GetInt32(1, 10);
            int x = RandomNumberGenerator.GetInt32(-5, 5);
            int b = RandomNumberGenerator.GetInt32(-10, 10);
            int y = RandomNumberGenerator.GetInt32(-5, 5);


สุ่ม และ คำนวณค่าออกมาเป็น สมการ เรียบร้อยแล้ว
แต่พอ เรามาหาค่า x y กลับไม่ใช่จำนวนเต็ม(ทั้งๆที่ สุ่มมาเป็นจำนวนเต็ม แน่ๆ)

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2023-06-08 18:45:48 By : lamaka.tor
 

 

No. 3



โพสกระทู้ ( 4,436 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

พอได้มีเวลานั่งงมโค้ด ก็พบว่า ผมเขียน ชุดรับค่าจากตัวดำเนินการผิดไป ครับ
ตอนนี้ใช้ได้แล้ว

Code (C#)
private string _Equation()
        {
            string s = "";
            int a = RandomNumberGenerator.GetInt32(1, 10);
            int x = RandomNumberGenerator.GetInt32(-5, 5);
            int b = RandomNumberGenerator.GetInt32(-10, 10);
            int y = RandomNumberGenerator.GetInt32(-5, 5);
            int d = RandomNumberGenerator.GetInt32(1, 3000);

            string o = (RandomNumberGenerator.GetInt32(1, 1000) > 500) ? "+" : "-";
            string ev = "";
            string _a, _b, _c;

            _a = intTostring(a);
            _b = intTostring(b);

            switch (d)
            {
                case int n when (n >= 0 && n < 1000):
                    //ax+/-by=0

                    do
                    {
                        a = RandomNumberGenerator.GetInt32(1, 10);
                        x = RandomNumberGenerator.GetInt32(-5, 5);
                        b = RandomNumberGenerator.GetInt32(-10, 10);
                        y = RandomNumberGenerator.GetInt32(-5, 5);

                        o = (RandomNumberGenerator.GetInt32(1, 1000) > 500) ? "+" : "-";
                    } while (a * x + (o == "+" ? b * y : -b * y) != 0);

                    _a = intTostring(a);
                    _b = intTostring(b);
                    ev = $"{_a}x {o} {_b}y = 0";
                    break;

                case int n when (n >= 1000 && n < 2000):
                    //ax+/-by=c
                    int c = (o == "+") ? a * x + b * y : a * x - b * y;
                    ev = $"{_a}x {o} {_b}y = {c}";
                    break;

                case int n when (n >= 2000 && n <= 3000):
                    //ax = b+/-cy
                    int cValue = RandomNumberGenerator.GetInt32(1, 10);
                    int cy = cValue * y;
                    int cResult = (o == "+") ? a * x + cy : a * x - cy;
                    _c = intTostring(cValue);

                    if (o == "+")
                        ev = $"{_a}x = {_b}y {o} {cResult}";
                    else
                        ev = $"{_a}x = {_b}y {o} {cResult}";

                    break;
            }

            s = ev;

            a = RandomNumberGenerator.GetInt32(1, 10);
            b = RandomNumberGenerator.GetInt32(-10, 10);
            d = RandomNumberGenerator.GetInt32(1, 3000);

            o = (RandomNumberGenerator.GetInt32(1, 1000) > 500) ? "+" : "-";
            _a = intTostring(a);
            _b = intTostring(b);

            switch (d)
            {
                case int n when (n >= 0 && n < 1000):
                    //ax+/-by=0

                    do
                    {
                        a = RandomNumberGenerator.GetInt32(1, 10);
                        x = RandomNumberGenerator.GetInt32(-5, 5);
                        b = RandomNumberGenerator.GetInt32(-10, 10);
                        y = RandomNumberGenerator.GetInt32(-5, 5);

                        o = (RandomNumberGenerator.GetInt32(1, 1000) > 500) ? "+" : "-";
                    } while (a * x + (o == "+" ? b * y : -b * y) != 0);

                    _a = intTostring(a);
                    _b = intTostring(b);
                    ev = $"{_a}x {o} {_b}y = 0";
                    break;

                case int n when (n >= 1000 && n < 2000):
                    //ax+/-by=c
                    int c = (o == "+") ? a * x + b * y : a * x - b * y;
                    ev = $"{_a}x {o} {_b}y = {c}";
                    break;

                case int n when (n >= 2000 && n <= 3000):
                    //ax = b+/-cy
                    int cValue = RandomNumberGenerator.GetInt32(1, 10);
                    int cy = cValue * y;
                    int cResult = (o == "+") ? a * x + cy : a * x - cy;
                    _c = intTostring(cValue);

                    if (o == "+")
                        ev = $"{_a}x = {_b}y {o} {cResult}";
                    else
                        ev = $"{_a}x = {_b}y {o} {cResult}";

                    break;
            }

            return $"{s} and {ev}".Replace("--", "+").Replace("+-", "-").Replace("-+", "-")
                    .Replace("- -", "+").Replace("+ -", "-").Replace("- +", "-");
        }

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2023-06-08 23:24:37 By : lamaka.tor
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : C# WinApp รบกวนช่วยตรวจสอบโค้ด ให้หน่อยครับ ต้องการให้ค่า x y เป็นจะนวนเต็ม ครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 00
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่