Showing posts with label legal age checker using switch statement in c#. Show all posts
Showing posts with label legal age checker using switch statement in c#. Show all posts

Friday, October 20, 2017

Legal Age Checker Using Switch Statement in C#

I wrote this simple program in C# as an example for my upcoming book on C# programming what does the program will do is to check if the given age of the user is already an adult or not using switch statement in C#. The code is very easy to understand and use I hope you will find my work useful.

I am currently accepting programming work kindly contact me in the following email address for further details. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental is (034) 4335675.




Sample Program Output


Program Listing

legal.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

/* Legal Age Checker                                */
/* Author : Mr. Jake R. Pomperada, MAED-IT          */
/* Date   : November 20, 2016    Sunday 10:25 AM    */
/* Tool   : C#                                      */

namespace legal_age
{
    class legal_age
    {
        static void Main(string[] args)
        {
            string reply;
            int n = 0;
            int age = 0;

            do
            {
                Console.Clear();
                Console.Write("Legal Age Checker ");
                Console.Write("\n\n");
                Console.Write("Enter Your Age    : ");
                age = Convert.ToInt32(Console.ReadLine());

                switch(age) {
                    case 1: case 2: case 3:  case 4: case 5: case 6:
                    case 7: case 8: case 9:  case 10: case 11: case 12:
                    case 13: case 14:  case 15: case 16: case 17:
                    Console.Write("\n\n");
                    Console.WriteLine("At the age {0} you are still a Minor.", age);
                    break;
                    default:
                    Console.Write("\n\n");
                    Console.WriteLine("At the age {0} you are already an Adult.", age);
                   break;
                  }
                Console.Write("\n\n");
                Console.Write("Do You Want To Continue? Y/N : ");
                reply = Console.ReadLine();

                if (reply == "y" || reply == "Y")
                {
                    continue;
                }
                else if (reply == "n" || reply == "N")
                {
                    Console.Write("\n\n");
                    Console.Write("Thank You For Using This Software.");
                    Console.Write("\n\n");
                    break;
                }

            } while (n == 0);
            Console.ReadLine();
        }
    }
}