要写1个程式是叫 用户 输入他们的名字 ,还有 ID numberusing System;namespace IC_Systems
{ class Class1
{
[STAThread]
static void Main(string[] args)
{
Console.Write("Please enter your full name: ");
string name = Console.ReadLine();
Console.Write("Please enter your IC#: ");
string icnum = Console.ReadLine();
Console.WriteLine
("Name of resident: {0}", name);
Console.WriteLine
("Date of birth: 19{0}" ,idum);
Console.WriteLine
("Gender: {0}" ,sex);
Console.WriteLine
("type: {0}" ,type); }
}
}名字部分已经完成了
现在剩下id number 的部分不会
Console.Write("Please enter your ID number number: " ;
string idnum = Console.ReadLine();我要将 user 输入的id号码 做计算
要怎樣分?user 输入的號碼 是 12個號碼 xxxxxx-xx-xxxx
int idnum [11] 这样对吗?
(输入时 , 不要有 - 如果有 - 出 Console.Write("Error"); (然后叫用户 再输入过 ,不要终止程式)
然后做计算例如 861122339916得到的答案是 生日日期 = 22 号 11 月 86年
意思说 array 0,1 是年份 ,array 2,3 是月 , array 4,5 是 日期
之后 array 6 , 7 要组合 起来
int sum = ( idnum [ 6 ] * 10 ) + idnum [ 7 ] ;然后做1堆 case
例如 861122339916 的array 6 和7 加起来是 30 +3 = 33
case 1 01, 21, 22, 23, 24A = Applecase 202, 25, 26, 27 ,33A = Orange 等等 ...33 在 case 2 , 所以 A = Orange
还有就是最后1个 号码 弟 12个 号码 是算单数 or 双数
单数=男生 双数 = 女生if idnum [11] = ( ( idnum [ 11 ] % 2 ) == 0 ) ;
then gender = femaleeals male
--------------------------------------------例: 名字 aabbcc IDnum : 810503 78 4443
答案 名: aabbcc
答案1: 03日05月81年
答案2: orange
答案3: 男--------------------------------------------
不懂C# 的coding 要怎麼寫 有人可以教嗎?讲到好像很乱,希望有人看的明白
{ class Class1
{
[STAThread]
static void Main(string[] args)
{
Console.Write("Please enter your full name: ");
string name = Console.ReadLine();
Console.Write("Please enter your IC#: ");
string icnum = Console.ReadLine();
Console.WriteLine
("Name of resident: {0}", name);
Console.WriteLine
("Date of birth: 19{0}" ,idum);
Console.WriteLine
("Gender: {0}" ,sex);
Console.WriteLine
("type: {0}" ,type); }
}
}名字部分已经完成了
现在剩下id number 的部分不会
Console.Write("Please enter your ID number number: " ;
string idnum = Console.ReadLine();我要将 user 输入的id号码 做计算
要怎樣分?user 输入的號碼 是 12個號碼 xxxxxx-xx-xxxx
int idnum [11] 这样对吗?
(输入时 , 不要有 - 如果有 - 出 Console.Write("Error"); (然后叫用户 再输入过 ,不要终止程式)
然后做计算例如 861122339916得到的答案是 生日日期 = 22 号 11 月 86年
意思说 array 0,1 是年份 ,array 2,3 是月 , array 4,5 是 日期
之后 array 6 , 7 要组合 起来
int sum = ( idnum [ 6 ] * 10 ) + idnum [ 7 ] ;然后做1堆 case
例如 861122339916 的array 6 和7 加起来是 30 +3 = 33
case 1 01, 21, 22, 23, 24A = Applecase 202, 25, 26, 27 ,33A = Orange 等等 ...33 在 case 2 , 所以 A = Orange
还有就是最后1个 号码 弟 12个 号码 是算单数 or 双数
单数=男生 双数 = 女生if idnum [11] = ( ( idnum [ 11 ] % 2 ) == 0 ) ;
then gender = femaleeals male
--------------------------------------------例: 名字 aabbcc IDnum : 810503 78 4443
答案 名: aabbcc
答案1: 03日05月81年
答案2: orange
答案3: 男--------------------------------------------
不懂C# 的coding 要怎麼寫 有人可以教嗎?讲到好像很乱,希望有人看的明白
结合楼主的代码写了一个框子,具体内容自己添加。
class Class1
{
[STAThread]
static void Main(string[] args)
{
bool canExit = false;
//这个循环
while (!canExit )
{
Console.Write("Please enter your full name: ");
string name = Console.ReadLine(); Console.Write("Please enter your IC#: ");
string icnum = Console.ReadLine(); //xxxxxx xx xxxx check
Int64 res;
if (Int64.TryParse(icnum, out res))
{
//id读取成功
canExit = true;
}
else
{
Console.Write("Error");
continue;
} //自己的逻辑处理
// Console.WriteLine
("Name of resident: {0}", name);
Console.WriteLine
("Date of birth: 19{0}", idum);
Console.WriteLine
("Gender: {0}", sex);
Console.WriteLine
("type: {0}", type);
} }
if (Int64.TryParse(icnum, out res))
改成-----〉
long res;
if(long.TryParse(icnum,out res));
'long' does not contain a definition for 'TryParse'
static void Main(string[] args)
{
string name = "";
while (name.Length == 0)
{
Console.Write("Please enter your full name: ");
name = Console.ReadLine();
} string icnum = "";
while (icnum.Length == 0)
{
Console.Write("Please enter your IC#: ");
icnum = Console.ReadLine().Trim();
if (icnum.Length == 12 && icnum.IndexOfAny(new char[]{'-', '.'}) < 0)
{
long nNum = 0;
if (long.TryParse(icnum, out nNum))
{
break;
}
}
Console.WriteLine("Error");
icnum = "";
} string year = icnum.Substring(0, 2);
string month = icnum.Substring(2, 2);
string day = icnum.Substring(4, 2);
string sum = icnum.Substring(6, 2);
bool gender = (icnum[11] % 2 == 1); string a = "";
if ("01, 21, 22, 23, 24".IndexOf(sum) > 0)
{
a = "apple";
}
else if ("02, 25, 26, 27 ,33 ".IndexOf(sum) > 0)
{
a = "orange";
}
else
{
a = "unknown";
} Console.WriteLine("答案 名: {0}\n", name);
Console.WriteLine("答案1:{0}日{1}月{2}年\n", day, month, year);
Console.WriteLine("答案2:{0}\n", a);
Console.WriteLine("答案3:{0}\n", gender ? "男" : "女"); Console.ReadLine();
}
string A= icnum.Replace("-","");请问一下如果我这样写, 例如 881122-11
array 6和7 会是 1吗?
谢谢可是不懂为什么
if (long.TryParse(icnum, out nNum)) 还是有error一直说 'long' does not contain a definition for 'TryParse'我是用 Microsoft Visual Studio .NET 2003 ,是不是版本的问题?
{ class Class1
{
[STAThread]
static void Main(string[] args)
{
string name = "";
while (name.Length == 0)
{
Console.Write("Please enter your full name: ");
name = Console.ReadLine();
}
try
{ string icnum = "";
while (icnum.Length == 0)
{
Console.Write("Please enter your IC#: ");
icnum = Console.ReadLine().Trim();
if (icnum.Length == 12 && icnum.IndexOfAny(new char[]{'-', '.'}) < 14)
{
}
else
{
string b= icnum.Replace("-",string.Empty);
}
{
string b= icnum.Replace("-",string.Empty); string year = b.Substring(0, 2);
string month = b.Substring(2, 2);
string day = b.Substring(4, 2);
string sum = b.Substring(6, 2);
bool gender = (b[11] % 2 == 1);
string c;
if ("01, 21, 22, 23, 24".IndexOf(sum) > 0)
{
c = "apple";
}
else if ("02, 25, 26, 27 ,33 ".IndexOf(sum) > 0)
{
c = "orange";
}
else
{
c = "unknown";
} Console.WriteLine("\nName: {0}", name);
Console.WriteLine("DOB:{0}/{1}/{2}", day, month, year);
Console.WriteLine("CITY:{0}", c);
Console.WriteLine("Gender:{0}", gender ? "Boy" : "Girl");
} } }
catch
{
Console.WriteLine("\nuser may input the incorrect format, please try again.");
} }
}
}如果这样写用户输入 xxxxxxxxxxxxx or xxxxxx-xx-xxxx 都可以计算
可是如果用户输入超过位数 xxxxxx-xx-xxxxxxxx 还是会计算计算 =.="
如果用户输入 xxxxxxxxxxasdasfsdf (数字 + 英文 ) ,程式不会出错误,而且还是继续计算 @_@"要怎么改?