 |
|
C# WinApp รบกวนช่วยตรวจสอบโค้ด ให้หน่อยครับ ต้องการให้ค่า x y เป็นจะนวนเต็ม ครับ |
|
 |
|
|
 |
 |
|
โค้ด ครับ
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("- +", "-");
}
เหมือน ทดสอบแล้ว หลายๆ ค่าออกมาไม่ได้จำนวนเต็ม ครับ


Tag : .NET, Win (Windows App), C#
|
|
 |
 |
 |
 |
Date :
2023-06-07 16:31:39 |
By :
lamaka.tor |
View :
415 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ก่อนอื่นต้องรู้ว่าจะทำอะไรก่อน
ให้แก้สมการ หรือ สร้างสมการ หรือ เทียบสมการ หรืออื่นใด
หรือ เอาคำถามจาก ChatGPT มาด้วย
แต่ถ้าไม่สะดวก ตามที่ผมเคยบอก
AI ณ ปัจจุบัน ยังทำงานที่ซับซ้อนและปริมาณมากไม่ได้
และถ้าต้องการคำตอบที่แม่นยำกว่าเดิม
ควรถามมันเป็นภาษาอังกฤษ
แก้ที่ต้นเหตุง่ายกว่าปลายเหตุ
|
 |
 |
 |
 |
Date :
2023-06-07 21:02:11 |
By :
009 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พอได้มีเวลานั่งงมโค้ด ก็พบว่า ผมเขียน ชุดรับค่าจากตัวดำเนินการผิดไป ครับ
ตอนนี้ใช้ได้แล้ว
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 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|