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

C# help !!

mz.sunshine

New Member
Joined
Apr 18, 2013
Messages
4 (0.00/day)
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:

Kreij

Senior Monkey Moderator
Joined
Feb 6, 2007
Messages
13,817 (2.20/day)
Location
Cheeseland (Wisconsin, USA)
So what have you got so far?
 

mz.sunshine

New Member
Joined
Apr 18, 2013
Messages
4 (0.00/day)
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

Senior Monkey Moderator
Joined
Feb 6, 2007
Messages
13,817 (2.20/day)
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.
 

mz.sunshine

New Member
Joined
Apr 18, 2013
Messages
4 (0.00/day)
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

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
26,259 (4.63/day)
Location
IA, USA
System Name BY-2021
Processor AMD Ryzen 7 5800X (65w eco profile)
Motherboard MSI B550 Gaming Plus
Cooling Scythe Mugen (rev 5)
Memory 2 x Kingston HyperX DDR4-3200 32 GiB
Video Card(s) AMD Radeon RX 7900 XT
Storage Samsung 980 Pro, Seagate Exos X20 TB 7200 RPM
Display(s) Nixeus NX-EDG274K (3840x2160@144 DP) + Samsung SyncMaster 906BW (1440x900@60 HDMI-DVI)
Case Coolermaster HAF 932 w/ USB 3.0 5.25" bay + USB 3.2 (A+C) 3.5" bay
Audio Device(s) Realtek ALC1150, Micca OriGen+
Power Supply Enermax Platimax 850w
Mouse Nixeus REVEL-X
Keyboard Tesoro Excalibur
Software Windows 10 Home 64-bit
Benchmark Scores Faster than the tortoise; slower than the hare.
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.
 
Top