• We've upgraded our forums. Please post any issues/requests in this thread.

C# help !!

Joined
Apr 18, 2013
Messages
4 (0.00/day)
Likes
0
#1
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
Staff member
Joined
Feb 6, 2007
Messages
13,817 (3.49/day)
Likes
5,524
Location
Cheeseland (Wisconsin, USA)
Processor Intel Core 2 Quad QX9650 Extreme @ 3.0 GHz
Motherboard Asus Rampage Formula
Cooling ZeroTherm Nirvana NV120 Premium
Memory 8GB (4 x 2GB) Corsair Dominator PC2-8500
Video Card(s) 2 x Sapphire Radeon HD6970
Storage 2 x Seagate Barracuda 320GB in RAID 0
Display(s) Dell 3007WFP 30" LCD (2560 x 1600)
Case Thermaltake Armor w/ 250mm Side Fan
Audio Device(s) SupremeFX 8ch Audio
Power Supply Thermaltake Toughpower 750W Modular
Software Win8 Pro x64 / Cat 12.10
#2
So what have you got so far?
 
Joined
Apr 18, 2013
Messages
4 (0.00/day)
Likes
0
#3
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
Staff member
Joined
Feb 6, 2007
Messages
13,817 (3.49/day)
Likes
5,524
Location
Cheeseland (Wisconsin, USA)
Processor Intel Core 2 Quad QX9650 Extreme @ 3.0 GHz
Motherboard Asus Rampage Formula
Cooling ZeroTherm Nirvana NV120 Premium
Memory 8GB (4 x 2GB) Corsair Dominator PC2-8500
Video Card(s) 2 x Sapphire Radeon HD6970
Storage 2 x Seagate Barracuda 320GB in RAID 0
Display(s) Dell 3007WFP 30" LCD (2560 x 1600)
Case Thermaltake Armor w/ 250mm Side Fan
Audio Device(s) SupremeFX 8ch Audio
Power Supply Thermaltake Toughpower 750W Modular
Software Win8 Pro x64 / Cat 12.10
#4
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.
 
Joined
Apr 18, 2013
Messages
4 (0.00/day)
Likes
0
#6
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
20,903 (6.25/day)
Likes
9,994
Location
IA, USA
System Name BY-2015
Processor Intel Core i7-6700K (4 x 4.00 GHz) w/ HT and Turbo on
Motherboard MSI Z170A GAMING M7
Cooling Scythe Kotetsu
Memory 2 x Kingston HyperX DDR4-2133 8 GiB
Video Card(s) PowerColor PCS+ 390 8 GiB DVI + HDMI
Storage Crucial MX300 275 GB, Seagate 6 TB 7200 RPM
Display(s) Samsung SyncMaster T240 24" LCD (1920x1200 HDMI) + Samsung SyncMaster 906BW 19" LCD (1440x900 DVI)
Case Coolermaster HAF 932 w/ USB 3.0 5.25" bay
Audio Device(s) Realtek Onboard, Micca OriGen+
Power Supply Enermax Platimax 850w
Mouse SteelSeries Sensei RAW
Keyboard Tesoro Excalibur
Software Windows 10 Pro 64-bit
Benchmark Scores Faster than the tortoise; slower than the hare.
#7
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.