1. Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

C# help !!

Discussion in 'Programming & Webmastering' started by mz.sunshine, Apr 18, 2013.

  1. mz.sunshine New Member

    Joined:
    Apr 18, 2013
    Messages:
    4 (0.01/day)
    Thanks Received:
    0
    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
    Last edited: Apr 18, 2013
  2. Kreij

    Kreij Senior Monkey Moderator Staff Member

    Joined:
    Feb 6, 2007
    Messages:
    13,881 (5.27/day)
    Thanks Received:
    5,610
    Location:
    Cheeseland (Wisconsin, USA)
    So what have you got so far?
  3. mz.sunshine New Member

    Joined:
    Apr 18, 2013
    Messages:
    4 (0.01/day)
    Thanks Received:
    0
    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
  4. Kreij

    Kreij Senior Monkey Moderator Staff Member

    Joined:
    Feb 6, 2007
    Messages:
    13,881 (5.27/day)
    Thanks Received:
    5,610
    Location:
    Cheeseland (Wisconsin, USA)
    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.
  5. mz.sunshine New Member

    Joined:
    Apr 18, 2013
    Messages:
    4 (0.01/day)
    Thanks Received:
    0
    okay
  6. mz.sunshine New Member

    Joined:
    Apr 18, 2013
    Messages:
    4 (0.01/day)
    Thanks Received:
    0
    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.");
    }
  7. FordGT90Concept

    FordGT90Concept "I go fast!1!11!1!"

    Joined:
    Oct 13, 2008
    Messages:
    12,994 (6.44/day)
    Thanks Received:
    3,094
    Location:
    IA, USA
    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.
    Crunching for Team TPU

Currently Active Users Viewing This Thread: 1 (0 members and 1 guest)

Share This Page