CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2012

    C# learning assignment

    Iam taking computer programming in school and we are learning C#. and when I say learning I really mean is reading the C# textbook and trying to figure out what everything means. My buddy and I are just on chapter 2 of the C# textbook and the teacher does not know anything we are self teching ourselves. Now the teacher gave us this assignment even though we are only on chapter 2 and he expects us to do it. can anyone give me some help with this?

    we are using Microsoft Visual C# 2010 Express

    Q2: Write a C# program that has a Main method and a user-defined method called
    ComputeSalesTax. The Main method asks the user to enter an itemís cost (double) and the
    percentage sales tax (double). It then calls the method named ComputeSalesTax which has
    two parameters that will hold the itemís cost and percentage sales tax as arguments. The
    method returns the overall price of the item (double). For example, if an itemís cost is $3.50
    and percentage sales tax is 10% (which is entered as 0.1), then the value returned by the
    ComputeSalesTax is $3.85. The method header for ComputeSalesTax should look like:
    public static double ComputeSalesTax (double itemCost, double perSalesTax)
    For both questions, you are to submit your properly documented source code (ie, use
    comments), sample output showing your program works (ie, cut and paste from your output
    screens into a word processor), and your executable (ie, your .exe file). These are to be
    attached to the Assign 1 Ė Q1 and Assign 1 Ė Q2 dropboxes in WebCT respectively.
    **** Note: On this assignment you do not need to validate user input. This means that if the
    program requests a double, you can assume that the user will input a double, etc

  2. #2
    Join Date
    Apr 2012

    Re: C# learning assignment

    can provide u wid a sample program where u can change variables and edit the program to suite your question:

    using System;
    public class Payroll
    public static void Main()
    string name, ssn, entry;
    double rate, hours, gross, fed, state, net;
    const double FEDTAX = 0.15;
    const double STATETAX = 0.05;
    Console.Write("Enter your name: ");
    name = Console.ReadLine();
    Console.Write("Social Security number: ");
    ssn = Console.ReadLine();
    Console.Write("Hourly pay rate: ");
    entry = Console.ReadLine();
    rate = Convert.ToDouble(entry);
    Console.Write("Hours worked: ");
    entry = Console.ReadLine();
    hours = Convert.ToDouble(entry);
    gross = rate * hours;
    fed = gross * FEDTAX;
    state = gross * STATETAX;
    net = gross - fed - state;
    Console.WriteLine("\nPayroll Summary for: {0}\nSSN: {1}\nYou earned {2} at {3} per hour",
    name, ssn, hours.ToString("c"), rate.ToString("C"));
    Console.WriteLine("\nGross pay: {0, 10}", gross.ToString("c"));
    Console.WriteLine("Federal withholding: {0, 10}", fed.ToString("c"));
    Console.WriteLine("State withholding : {0, 10}", state.ToString("c"));
    Console.WriteLine("Net pay: {0, 10}", net.ToString("c"));


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.