Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Conquer Online 2 > CO2 Programming
You last visited: Today at 05:45

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[General C# Coding] Help

Discussion on [General C# Coding] Help within the CO2 Programming forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
Rofa300's Avatar
 
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;
        }
    }
}
Rofa300 is offline  
Old 03/03/2009, 03:00   #2
 
leavemealone's Avatar
 
elite*gold: 0
Join Date: May 2006
Posts: 2,168
Received Thanks: 8,593
Wrong section.

#Moved
leavemealone is offline  
Old 03/03/2009, 06:19   #3
 
andyd123's Avatar
 
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
andyd123 is offline  
Old 03/05/2009, 22:20   #4
 
Rofa300's Avatar
 
elite*gold: 0
Join Date: Jul 2007
Posts: 105
Received Thanks: 45
thx Andy
Rofa300 is offline  
Old 03/05/2009, 23:41   #5
 
andyd123's Avatar
 
elite*gold: 20
Join Date: Apr 2006
Posts: 1,341
Received Thanks: 886
Not a problem
andyd123 is offline  
Old 03/06/2009, 20:59   #6
 
unknownone's Avatar
 
elite*gold: 20
Join Date: Jun 2005
Posts: 1,013
Received Thanks: 381
Quote:
Originally Posted by andyd123 View Post
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.
unknownone is offline  
Old 03/11/2009, 20:54   #7
 
Rofa300's Avatar
 
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
Rofa300 is offline  
Reply


Similar Threads Similar Threads
Good News To all Brigadier General-General of the Army
11/23/2009 - Soldier Front - 2 Replies
if you want to view your EXP if ur Brigadier General to General of the Army click this !! ?SF?Special Force to view ur EXP!!!!



All times are GMT +1. The time now is 05:45.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.