|
You last visited: Today at 05:45
Advertisement
[General C# Coding] Help
Discussion on [General C# Coding] Help within the CO2 Programming forum part of the Conquer Online 2 category.
03/01/2009, 02:56
|
#1
|
elite*gold: 0
Join Date: Jul 2007
Posts: 105
Received Thanks: 45
|
[General C# Coding] Help
So as Many of u Know or Don't, am Learning C# and Till School Is Over My Learning Progress Will be SLOW.However, i tried to Make a Simple Program That Do Every thing this Pic Shows

Now i need to Know how to make The User CHOOSE From Multi Options , like to Add [Mr , Mrs ... etc] , Emme Showed me b4 but i lost it b4 i look at it ...
Here is The Code
Code:
static void Main(string[] args)
{
StartLabel:
try
{
Console.Write("What is Your Name: ");
string Name1 = Console.ReadLine();
Console.Write("What is Your Mid Name: ");
string Name2 = Console.ReadLine();
Console.Write("What is Your Last Name: ");
string Name3 = Console.ReadLine();
Console.WriteLine("What Is Your Birth Year?");
int year = int.Parse(Console.ReadLine());
Console.WriteLine("What Is Your Birth Month? ");
int month = int.Parse(Console.ReadLine());
Console.WriteLine("What Is Your Birth Day? ");
int day = int.Parse(Console.ReadLine());
DateTime myDOB = new DateTime(year, month, day);
int age = CalcAge(myDOB);
Console.WriteLine(" ");
Console.WriteLine(" ");
Console.WriteLine("Hello" + " " + Name1 + " " + Name2 + " " + Name3 + " " +"You Are {0} Years Old.", age);
Console.WriteLine(" ");
Console.WriteLine(" ");
Console.WriteLine(" ");
Console.WriteLine("Press Any Key To Close The Program ...");
Console.ReadLine();
}
catch(Exception)
{
Console.WriteLine("Invaild Input , Please Try Again . . . ");
Console.ReadLine();
goto StartLabel;
}
}
public static int CalcAge(DateTime DateOfBirth)
{
DateTime now = DateTime.Today;
int years = now.Year - DateOfBirth.Year;
if (now.DayOfYear < DateOfBirth.DayOfYear)
--years;
return years;
}
}
}
|
|
|
03/03/2009, 03:00
|
#2
|
elite*gold: 0
Join Date: May 2006
Posts: 2,168
Received Thanks: 8,593
|
Wrong section.
#Moved
|
|
|
03/03/2009, 06:19
|
#3
|
elite*gold: 20
Join Date: Apr 2006
Posts: 1,341
Received Thanks: 886
|
One way you could do this, without giving away that you are trying to determine Mrs, Mr, or Ms would be like this...
Code:
spublic static void Main(string[] args)
{
StartLabel:
try
{
Console.Write("What is Your Name: ");
string Name1 = Console.ReadLine();
Console.Write("What is Your Mid Name: ");
string Name2 = Console.ReadLine();
Console.Write("What is Your Last Name: ");
string Name3 = Console.ReadLine();
Console.Write("Are you a man or woman? ");
bool man = true;
string sex = Console.ReadLine();
if(sex.Contains("wo"))
man = false;
Console.Write("Are you married? ");
string married = Console.ReadLine();
bool married2 = false;
if(married.Contains("y"))
married2 = true;
Console.WriteLine("What Is Your Birth Year?");
int year = int.Parse(Console.ReadLine());
Console.WriteLine("What Is Your Birth Month? ");
int month = int.Parse(Console.ReadLine());
Console.WriteLine("What Is Your Birth Day? ");
int day = int.Parse(Console.ReadLine());
DateTime myDOB = new DateTime(year, month, day);
int age = CalcAge(myDOB);
Console.WriteLine(" ");
Console.WriteLine(" ");
if(man)
{
Console.WriteLine("Hello" + " Mr. " + Name1 + " " + Name2 + " " + Name3 + " " +"You Are {0} Years Old.", age);
}
else if(!man && !married2)
{
Console.WriteLine("Hello" + " Ms. " + Name1 + " " + Name2 + " " + Name3 + " " +"You Are {0} Years Old.", age);
}
else
{
Console.WriteLine("Hello" + " Mrs. " + Name1 + " " + Name2 + " " + Name3 + " " +"You Are {0} Years Old.", age);
}
Console.WriteLine(" ");
Console.WriteLine(" ");
Console.WriteLine(" ");
Console.WriteLine("Press Any Key To Close The Program ...");
Console.ReadLine();
}
catch(Exception)
{
Console.WriteLine("Invaild Input , Please Try Again . . . ");
Console.ReadLine();
goto StartLabel;
}
}
public static int CalcAge(DateTime DateOfBirth)
{
DateTime now = DateTime.Today;
int years = now.Year - DateOfBirth.Year;
if (now.DayOfYear < DateOfBirth.DayOfYear)
--years;
return years;
}
It is entirely possible to do this other ways, even ways that use less lines of code, but you can always figure those out
|
|
|
03/05/2009, 22:20
|
#4
|
elite*gold: 0
Join Date: Jul 2007
Posts: 105
Received Thanks: 45
|
thx Andy
|
|
|
03/05/2009, 23:41
|
#5
|
elite*gold: 20
Join Date: Apr 2006
Posts: 1,341
Received Thanks: 886
|
Not a problem
|
|
|
03/06/2009, 20:59
|
#6
|
elite*gold: 20
Join Date: Jun 2005
Posts: 1,013
Received Thanks: 381
|
Quote:
Originally Posted by andyd123
One way you could do this, without giving away that you are trying to determine Mrs, Mr, or Ms would be like this...
It is entirely possible to do this other ways, even ways that use less lines of code, but you can always figure those out 
|
A good idea to do it in code, but not an ideal solution in a real environment. How someone likes to be addressed is preference, particlarly for women (Ie, Ms. or Miss.). You're also dropping chance for people to put other honorifics such as Dr.
IMO, it would be better to leave it open for text, or have a more complete list, maybe contained in an enum - where you'd be able to select which name to use with a number.
|
|
|
03/11/2009, 20:54
|
#7
|
elite*gold: 0
Join Date: Jul 2007
Posts: 105
Received Thanks: 45
|
@unknownone : what i wanted to Learn is HOW to show TEXT if the User Inputted Another Text Or Number , just for Learning
|
|
|
All times are GMT +1. The time now is 05:45.
|
|