# C# help !!



## mz.sunshine (Apr 18, 2013)

I am taking a C# class and I am totally lost on this week's assignment I haven't been able to get much hoping someone here can assist. Time is of the essence. Here is this weeks assignment:

One of your smaller customers needs your help writing a program. Your customer has an e-commerce Web site but wants to avoid being sued for allowing children to make purchases without the authorization of their parents. Using the 6 steps of problem solving, create a program to verify the age of a customer wishing to make an online purchase. The customer will enter his or her year of birth, and your program will calculate whether the customer is more than 18-years old. The program will then display a message to the customer that his or her purchase request is accepted or denied. 

Your solution must include the following 5 parts in addition to the coded solution:

1.A problem analysis chart with each of the following sections: 
◦Given information
◦Required results
◦Processing required to obtain the results
◦Solution alternatives 
2.A flowchart showing the program processing flow
3.A chart showing input, output, and processing
4.An algorithm in pseudo code describing the steps the program will perform
5.A description in 4–6 paragraphs of how each of the 6 problem-solving steps was addressed


----------



## Kreij (Apr 18, 2013)

So what have you got so far?


----------



## mz.sunshine (Apr 18, 2013)

Console.Out.WriteLine("Please enter the year you were born");
 Int32 age = DateTime.Now.Year - Convert.ToInt32(Console.ReadLine());if(age>18)
 Console.Out.WriteLine("You are approved to make a purchase.");else
 Console.Out.WriteLine("You are not approved to make a purchase.");

I know I need to get the age frome DateTime.Now.Year - year user entered


----------



## Kreij (Apr 18, 2013)

You can't just use the year someone was born. You have to use the day and month also to determine if they are actually 18 years old.

If I am 17 today and my birthday is not for a couple of months, but in the same year, you have to check for that.


----------



## mz.sunshine (Apr 18, 2013)

okay


----------



## mz.sunshine (Apr 18, 2013)

This is what I have but I am getting error messages:

String YearBorn:
            int YearBornInt;


        Console.Out.WriteLine("Please enter your year of birth (eg:1985).");
        YearBorn = Console.In.ReadLine();
        YearBornInt = Convert.ToInt32 (YearBorn);

        Int32 age = DateTime.Now.Year - Convert.ToInt32(Console.ReadLine());if(age>18)
 Console.Out.WriteLine("You are approved to make a purchase.");else
 Console.Out.WriteLine("You are not approved to make a purchase.");
    }


----------



## FordGT90Concept (Apr 18, 2013)

What I would do is make a function that:
-returns an int (zero if error)
-has display string like "Please enter your year of birth"
-has a do...while loop on the condition that int is not zero
--displays the string
--try statement
---read string
---if string to lower equals "exit" or "quit"
----return 0
---else
----convert string to int, store the int
--catch statement 
---display error message
---set int to zero
-returns int

Use that function to request the month, date, and year.  Once you have all three, create a new DateTime using those figures.  Subtract DateTime.Now from your created DateTime.  If the years in the resulting TimeSpan are less than 18, no entry.


----------

