Thread: Method Problem!

  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    208

    Method Problem!

    How do you share data between two or more methods using arguments or return values? In C#. I guess what I saying is how do you pass arguments to more than one function? I don't require a specific example just general terms

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Have you tried looking it up?

    Passing Arguments C#
    Last edited by prog-bman; 09-01-2014 at 04:27 AM.

  3. #3
    Registered User
    Join Date
    Jan 2010
    Posts
    208
    I think in books it talks about passing by value maybe that good enough I just haven't read it I guess I should try other resources before posting

  4. #4
    Registered User
    Join Date
    Jan 2010
    Posts
    208
    Well I learned how to do it. I'll post the code. So us noobs can look at it

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace Chapter9Problem11
    {
        class Program
        {
            static void Main()
            {
                double payRate = 0.0;
                double hoursWorked = 0.0;
                double grossPay = 0.0;
                double tax = 0.0;
                double netPay = 0.0;
    
                Console.Write("\nEnter pay rate: ");
                payRate = Convert.ToDouble(Console.ReadLine());
    
                Console.Write("\nEnter hours worked: ");
                hoursWorked = Convert.ToDouble(Console.ReadLine());
    
                grossPay = GrossPay(payRate, hoursWorked);
                tax = Tax(grossPay);
                netPay = NetPay(grossPay, tax);
    
    
                DisplayResults(grossPay, tax, netPay);
    
                Console.ReadLine();
    
            }
    
            static double GrossPay(double payRate, double hoursWorked)
            {
                double grossPay = 0.0;
    
                if (hoursWorked > 40)
                    grossPay = 40 * payRate + ((hoursWorked - 40) * (1.5 * payRate));
                else
                    grossPay = hoursWorked * payRate;
    
                return grossPay;
    
            }
    
            static double Tax(double grossPay)
            {
                return grossPay * .15;
            }
    
            static double NetPay(double grossPay, double tax)
            {
                return grossPay - tax;
            }
    
            static void DisplayResults(double grossPay,double tax,double netPay)
            {
                Console.Write("\nGross Pay: {0:C}",grossPay);
                Console.Write("\nTax: {0:C}", tax);
                Console.Write("\nNet Pay: {0:C}", netPay);
            }
        }
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with signal method
    By eryn in forum C Programming
    Replies: 4
    Last Post: 03-09-2010, 07:44 PM
  2. is there a problem in this method of casting?
    By transgalactic2 in forum C Programming
    Replies: 8
    Last Post: 07-27-2009, 11:50 PM
  3. Which is the best method for this problem??
    By kahwei in forum C Programming
    Replies: 12
    Last Post: 02-07-2009, 11:15 AM
  4. problem with the bisection method
    By dionys in forum C Programming
    Replies: 1
    Last Post: 04-01-2004, 04:19 PM
  5. class method problem
    By Corey in forum C++ Programming
    Replies: 4
    Last Post: 04-22-2003, 10:06 AM