1 // Student: Pat Moss www.patmoss.com/cis162ad/ 2 // Instructor: Dave Hammer http://members.cox.net/dwhammer/ 3 4 // CIS162AD -- C Sharp (C#) -- Section 5832 5 // Professor: Dave Hammer dwhammer@cox.net 6 // http://members.cox.net/dwhammer/ 7 // Student: Patrick Moss patmoss@patmoss.com 8 // http://www.patmoss.com/cis162ad/ 9 10 // Worksheet #2 11 // III. Programming Exercise 12 13 // Write a program that calculates and prints the take-home pay 14 // for a commissioned sales employee. Initialize and store the 15 // name of employee Jessica Oakley in a variable called 16 // employeeName. Jessica received 7% of her total sales. Her 17 // federal tax rate is 18%. She contributes 10% to a retirement 18 // fund and 6% to Social Security. Input the sales for the week. 19 // Produce a formatted report showing the amount for each of the 20 // computed items. Select appropriate constants to use in the 21 // calculations. Turn in your source code for this program. 22 23 // program name: takehomepay.cs rev. 01 02-04-2006 by pat moss 24 // textbook: Visual C# .NET Programming, Barbara Doyle, 0619159979 25 26 using System; 27 28 namespace takehomepay 29 { 30 class takehomepay 31 { 32 static void Main() 33 { 34 const decimal commrate = 0.07M; // commission rate = 7% 35 const decimal fedtaxrate = 0.18M; // federal tax rate = 18% 36 const decimal retirerate = 0.10M; // retirement rate = 10% 37 const decimal socsecrate = 0.06M; // soc sec rate = 6% 38 39 string employeeName = "Jessica Oakley"; 40 decimal commamt = 0; // commission amount 41 decimal fedtaxamt = 0; // fed tax amount 42 decimal retireamt = 0; // retirement amount 43 decimal socsecamt = 0; // soc sec amount 44 decimal grosssalesamt = 0; // gross sales amount 45 decimal totalwithholdingamt = 0; // total withholding amount 46 decimal takehomepayamt = 0; // take home pay amount 47 48 Console.WriteLine("Worksheet2 -- takehomepay.cs"); 49 Console.WriteLine("Student: Pat Moss"); 50 Console.WriteLine("Instructor: Dave Hammer"); 51 52 // read gross sales amount from the keyboard 53 Console.Write("\nEnter gross sales amount for Jessica Oakley: "); 54 grosssalesamt = Convert.ToDecimal(Console.ReadLine()); 55 56 // calculate sales commission and round to 2 decimal places 57 commamt = commrate * grosssalesamt; 58 commamt = Math.Round(commamt, 2); 59 60 // calculate withholding for federal tax, retirement, and soc sec 61 fedtaxamt = fedtaxrate * commamt; 62 retireamt = retirerate * commamt; 63 socsecamt = socsecrate * commamt; 64 65 // round withholding amounts to 2 decimal places 66 fedtaxamt = Math.Round(fedtaxamt, 2); 67 retireamt = Math.Round(retireamt, 2); 68 socsecamt = Math.Round(socsecamt, 2); 69 70 // calculate total withholding amount 71 totalwithholdingamt = fedtaxamt + retireamt + socsecamt; 72 73 // calculate net take home pay amount 74 takehomepayamt = commamt - totalwithholdingamt; 75 76 Console.WriteLine("Employee Name: {0}", employeeName); 77 Console.WriteLine("Gross Sales: {0:c}", grosssalesamt); 78 Console.WriteLine("Sales Commission: {0:c}", commamt); 79 Console.WriteLine("Federal Tax: {0:c}", fedtaxamt); 80 Console.WriteLine("Retirement: {0:c}", retireamt); 81 Console.WriteLine("Soc Sec Tax: {0:c}", socsecamt); 82 Console.WriteLine("Total Withholding: {0:c}", totalwithholdingamt); 83 Console.WriteLine("Take Home Pay: {0:c}", takehomepayamt); 84 } 85 } 86 }