Click here to Skip to main content
15,887,936 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 3 methods but i get 2 errors

Error 1 (No overload for method 'calculatePay' takes 0 arguments)
Error 2 (No overload for method 'DisplayPaySlip' takes 0 arguments)

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Prac4_s208050509_
{
    class Program
    {
        private static string message;
        static void Main(string[] args)
        {
            string calc;

            getDetails();
           
           calc= calculatePay();
           Console.WriteLine(calc);
            DisplayPaySlip();
           // Console.WriteLine(message);
           // Console.ReadLine();
            
        }
        public static void getDetails()
        {
            string fullName;
            string employeeNumber;
            double noOfHoursWorked;
            double hourlyRate;

            //I've set the hourlyRate to 50 for there was no default hourly rate given
            int count;
            Console.WriteLine("Please enter the number of employees");
            count = int.Parse(Console.ReadLine());

          for(int i =0;i<= count;i++)
            {
                Console.Write("Please enter your full name:");
                fullName = Console.ReadLine();
                Console.Write("Please enter your employee number:");
                employeeNumber = Console.ReadLine();
                Console.Write("Please enter the amount of hours worked:");
                noOfHoursWorked = double.Parse(Console.ReadLine());
                Console.Write("Please enter your hourly rate:");
                hourlyRate = double.Parse(Console.ReadLine());
               // count++;
            }
            //hourlyRate ;
        }
        public static  void calculatePay(ref double hourlyRate,ref double noOfHoursWorked)
        {
            //double overtime;
            double weeklyPay;
            if (noOfHoursWorked <= 40)
            {
                weeklyPay = noOfHoursWorked * hourlyRate;
                Console.WriteLine("Weeekly Pay:",weeklyPay);
                Console.ReadLine();
            }
            else
            {
                weeklyPay = (hourlyRate * 1.5)*noOfHoursWorked;
                Console.WriteLine("Overtime Pay",weeklyPay);
                Console.ReadLine();
                
            } 
            
        }
          public static void DisplayPaySlip(  string fullName, double noOfHoursWorked, string employeeNumber,string hourlyRate, double weeklyPay)
        {
            string message;
            message="Employee Number"+employeeNumber;
            message += "Full Name"+fullName;
            message += "Hours Worked"+noOfHoursWorked;
            message += "Hourly Rate"+hourlyRate;
            message += "Weekly Pay"+weeklyPay;

            Console.WriteLine(message);
            Console.ReadLine();
            

        }
    }
}
Posted
Updated 27-Mar-13 22:56pm
v2
Comments
Deliwe 28-Mar-13 5:00am    
do you have a solution to my problem

Look at your code:
C#
calc= calculatePay();
...
public static  void calculatePay(ref double hourlyRate,ref double noOfHoursWorked)
And

C#
DisplayPaySlip();
...
  public static void DisplayPaySlip(  string fullName, double noOfHoursWorked, string employeeNumber,string hourlyRate, double weeklyPay)

You have declared moth methods to take parameters, but you are not supplying them when you call the methods. Since the parameters look pretty important to doing the job the method is intended to do, tyou need to find them and supply them when you call the methods! I'm also pretty sure you want to return a value from teh CalculatePay method, rather than return a void - and there is no good reason for making the parameters ref since you don't (and shouldn't) change them.
C#
double rate = 15.0;
double hours = 48.0;
calc = calculatePay(ref rate, ref hours);
DiaplyPaySlip("Joe Blogs", 48, "666", "15.0", calc);


BTW: Why is your hourlyRate a string for the DisplayPaySlip method? Surely it would be better to use a double like you do for CalculatePay?
 
Share this answer
 
Hi,

you should pass the input parameters for both the methods.

C++
calculatePay(hourlyRate, noOfHoursWorked)

DisplayPaySlip(fullName, noOfHoursWorked, employeeNumber, hourlyRate, weeklyPay)


And getDetails() works fine because there is no input parameters.

Bye.
 
Share this answer
 
The error message is clear and pretty straightforward: you are calling the methods without providing the necessary arguments.
For instance, the method calculatePay takes two arguments (namely hourlyRate and noOfHoursWorked) while you are passing it none of them.

To fix the issue you may:
  • Make calculatePay directly called by getDetails method (since the latter holds the necessary info)

OR
  • Modify getDetails method in order to make collected data available to other members of the class (for instance you may have a list of Employes as class member, and make getDetails fill it).
 
Share this answer
 
Have a look and compare ;)
C#
static void Main(string[] args)
{
    string calc;

    getDetails();

   // Console.WriteLine(message);
   // Console.ReadLine();

}


cX
public static void getDetails()
   {
       string fullName;
       string employeeNumber;
       double noOfHoursWorked;
       double hourlyRate;
       double weeklyPay;

       //I've set the hourlyRate to 50 for there was no default hourly rate given
       int count;
       Console.WriteLine("Please enter the number of employees");
       count = int.Parse(Console.ReadLine());

     for(int i =0;i<= count;i++)
       {
           Console.Write("Please enter your full name:");
           fullName = Console.ReadLine();
           Console.Write("Please enter your employee number:");
           employeeNumber = Console.ReadLine();
           Console.Write("Please enter the amount of hours worked:");
           noOfHoursWorked = double.Parse(Console.ReadLine());
           Console.Write("Please enter your hourly rate:");
           hourlyRate = double.Parse(Console.ReadLine());
           weeklyPay = calculatePay(hourlyRate, noOfHoursWorked);
           DisplayPaySlip(fullName, noOfHoursWorked, employeeNumber, hourlyRate, weeklyPay);

          // count++;
       }
       //hourlyRate ;
   }

        public static  double calculatePay(ref double hourlyRate,ref double noOfHoursWorked)
        {
            double weeklyPay;
            if (noOfHoursWorked <= 40)
            {
                weeklyPay = noOfHoursWorked * hourlyRate;
                
            }
            else
            {
                weeklyPay = (hourlyRate * 1.5)*noOfHoursWorked;
            } 
            return weeklyPay;
        }            
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900