I am trying to write a program that asks the user to input their date of birth to verify if they are over 18. If they are I need to print "transaction approved" to the console and if not I need it to print "transaction denied."
The problem I am having is that I cannot compare a the values that I want in the if statement. Help!
Here is the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication7
{
class Program
{
public static void Main()
{
DateTime dateOfBirth, legalDate, currentDate;
TimeSpan currentAge;
Console.WriteLine("Please Enter Your Date of Birth");
dateOfBirth = Convert.ToDateTime(Console.ReadLine());
legalDate = DateTime.Now.AddYears(-18);
currentDate = DateTime.Now;
currentAge = currentDate.Subtract(dateOfBirth);
Console.WriteLine(
"As of " + currentDate + " you are: " + currentAge + " years old");
if ((currentAge < 18))
{
Console.WriteLine(
"Your transaction has been approved. Thank you.");
}
else
Console.WriteLine(
"You were not born on or before " + legalDate + ". Your transaction has been denied.");
}
}
}
The problem I am having is that I cannot compare a the values that I want in the if statement. Help!
Here is the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication7
{
class Program
{
public static void Main()
{
DateTime dateOfBirth, legalDate, currentDate;
TimeSpan currentAge;
Console.WriteLine("Please Enter Your Date of Birth");
dateOfBirth = Convert.ToDateTime(Console.ReadLine());
legalDate = DateTime.Now.AddYears(-18);
currentDate = DateTime.Now;
currentAge = currentDate.Subtract(dateOfBirth);
Console.WriteLine(
"As of " + currentDate + " you are: " + currentAge + " years old");
if ((currentAge < 18))
{
Console.WriteLine(
"Your transaction has been approved. Thank you.");
}
else
Console.WriteLine(
"You were not born on or before " + legalDate + ". Your transaction has been denied.");
}
}
}