這是我的完整程序。很顯然,我是一名初學者。我面對的問題是,如果年齡小於零,那麼它會返回幾行,但是它也會再次詢問用戶。 :(我能做些什麼來解決這個問題?C#標籤和轉到
using System;
namespace Examples
{
class Program
{
static void Main(string[] args)
{
string name;
string city;
int age;
int pin;
// \n is used for line-break
Console.Write("Enter your name : ");
name = Console.ReadLine();
Console.Write("\nEnter Your City : ");
city = Console.ReadLine();
age:
Console.Write("\nEnter your age : ");
age = Int32.Parse(Console.ReadLine());
Console.Write("\nEnter your pin : ");
pin = Int32.Parse(Console.ReadLine());
if (age < 0 || age >= 110)
{
goto age;
}
// Printing message to console
//formatting output
Console.WriteLine("==============");
Console.WriteLine("Your Complete Address:");
Console.WriteLine("============\n");
Console.WriteLine("Name = {0}", name);
Console.WriteLine("City = {0}", city);
Console.WriteLine("Age = {0}", age);
Console.WriteLine("Pin = {0}", pin);
Console.WriteLine("===============");
Console.ReadLine();
}
}
}
哦,請不要使用'goto'聲明 – 2014-10-28 08:52:32
你的新的,但你想失去你的魅力'儘快goto' :) – Tim 2014-10-28 08:52:50
的goto是壞的,你應該感覺不好。 – NaeiKinDus 2014-10-28 08:52:55