作業(yè)要求
為了維護(hù)用戶信息,需要將其信息錄入系統(tǒng),具體要求如下:
(1) .循環(huán)錄入用戶的信息,包括用戶編號、年齡、積分;(2) .判斷年齡是否合法,要求用戶必須滿10周歲以上。若年齡合法,則顯示錄入信息,否則顯示錄入失敗。
代碼
...
Console.WriteLine("請輸入用戶數(shù)量");
int count = Convert.ToInt32(Console.ReadLine());
int custNo = 0;
int age;
int points = 0;
for (int i = 1; i <= count; i++)
{
Console.WriteLine("請輸入第{0}位的用戶信息", i);
Console.WriteLine("請輸入用戶編號(<4位整數(shù):)");
custNo = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("請輸入用戶年齡");
age = Convert.ToInt32(Console.ReadLine());
if (age < 10 || age > 100)
{
Console.WriteLine("很抱歉,您的年齡不適宜玩游戲");
Console.WriteLine("錄入信息失敗");
continue;
}
Console.WriteLine("請輸入用戶積分:");
points = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("您錄入的用戶信息是:");
Console.WriteLine("用戶編號:" + custNo + "\t年齡:" + age + "\t積分:" + points + "\n");
}
Console.ReadKey();
...
效果
