 |
|
ช่วยดูโค้ดC#ให้หน่อย ต้องการเพิ่มและแก้ไขนิดหน่อย ตรง input x,y ให้ input เป็นตัวเลขเท่านั้น |
|
 |
|
|
 |
 |
|
ตรง input x,y ให้ input เป็นตัวเลขเท่านั้น ถ้าเป็นตัวอักษรจะวนลูปเพื่อรับค่า x,y อีกรอบจนกว่าผู้ใช้จะ input เป็นตัวเลข
- เป็นโค้ดคำนวณเลขที่ผู้ใช้ป้อนเข้ามา คือ x และ y ซึ้งจะคำนวณตั้งแต่การ บวก ลบ คูณ หาร และ หารหาเศษ
Code (C#)
char ans;
do
{
float result;
float x = 0;
float y = 0;
Console.Write("Input x:");
x = float.Parse(Console.ReadLine());
Console.Write("Input y:");
y = float.Parse(Console.ReadLine());
Console.WriteLine("_________________________");
result = x+y;
Console.WriteLine("{0}+{1} ={2,5}", x, y, result);
Console.WriteLine("_________________________");
result = x-y;
Console.WriteLine("{0}-{1} ={2,5}", x, y, result);
Console.WriteLine("_________________________");
result = x*y;
Console.WriteLine("{0}*{1} ={2,5}", x, y, result);
Console.WriteLine("_________________________");
result = x/y;
Console.WriteLine("{0}/{1} ={2,5}", x, y, result);
Console.WriteLine("_________________________");
result = x%y;
Console.WriteLine("{0}%{1} ={2,5}", x, y, result);
Console.WriteLine("_________________________");
Console.Write("Do you want exit....(y/n)?+++++++++++++++++++++++++++++++++++++++++");
ans = char.Parse(Console.ReadLine());
}while(ans=='n');
Tag : - - - -
|
|
 |
 |
 |
 |
Date :
2010-02-13 14:16:11 |
By :
DYonceDiiZZaS |
View :
1714 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (C#)
string input_x;
string input_y;
float x = 0;
float y = 0;
do
{
Console.Write("Input x:");
input_x = Console.ReadLine();
Console.Write("Input y:");
input_y = Console.ReadLine();
Console.WriteLine("_________________________");
} while (!IsNumber(input_x, input_y));
x = float.Parse(input_x);
y = float.Parse(input_y);
Code (C#)
static bool IsNumber(string x, string y)
{
bool isNum = true;
try
{
float.Parse(x);
float.Parse(y);
}
catch
{
isNum = false;
}
return isNum;
}
|
 |
 |
 |
 |
Date :
2010-02-13 18:06:06 |
By :
tungman |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (C#)
string s = "-.4";
System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(@"^([+]|[-]|[.]|[-.]|[0-9])[0-9]*[.]*[0-9]+$");
if (reg.IsMatch(s))
{
MessageBox.Show("hi");
}
เป็น Real Number
+1, -1, -.2, +12,-0.5,-4,+4 ฯลฯ ได้หมด
|
 |
 |
 |
 |
Date :
2010-02-15 10:17:16 |
By :
numenoy |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
รบกวนเขียน c# ให้ ดูด้วยได้มั้ยคะ
|
 |
 |
 |
 |
Date :
2011-08-05 10:51:22 |
By :
เนยจัง |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
รบกวนเขียน โฟลชาทร์ ให้ดูได้มั้ยคะ
|
 |
 |
 |
 |
Date :
2011-08-05 10:52:26 |
By :
เนยจัง |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|