4 Replies - 3794 Views - Last Post: 19 October 2012 - 05:46 PM Rate Topic: -----

#1 mathanor  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 19-October 12

No overload for 'Method' takes 0 arguments

Posted 19 October 2012 - 04:28 PM

I'm very new to C sharp so I apologize if I really screwed something up, lol.

I'm writing a two class application with an array to store 7 days of temperatures. I need to include methods to give the highest, lowest, average, average excluding the lowest and the number of days with temperatures lower than a user inputted temp. The second class is to test the first.

I obviously haven't finished because I'm getting errors trying to calculate the average ("No overload for 'GetAverage' takes 0 arguments").

First Class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace A13
{
    class WeeklyTemps
    {
        private int[] temps;
        private int average,
            sum,
            lowest,
            highest,
            highestWOLowest,
            inputTemp,
            range,
            noOfDays;

        public WeeklyTemps()
        {
        }

        public WeeklyTemps(int [] temps)
        {

        }

        public int GetAverage(int [] temps)
        {
            int sum = temps.Sum();
            average = sum / temps.Length;   

            return average;
        }

        public int GetLowest()
        {
            lowest = temps.Min();
            return lowest;
        }

        public int GetHighest()
        {
            return highest;
        }

        public int GetAverageWOLowest()
        {
            return highestWOLowest;
        }

        public int NoOfDays(int inputTemp)
        {
            return noOfDays;
        }

        public override string ToString()
        {
            string s = range.ToString();
            return s;

        }
    }
}



Second Class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            WeeklyTemps weeklyTemps1 = new WeeklyTemps(new int [] {71,72,73,74,75,76,77});
            Console.WriteLine(weeklyTemps1.GetAverage());

        }
    }
}



Any help is appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: No overload for 'Method' takes 0 arguments

#2 lukasz_ltt  Icon User is offline

  • New D.I.C Head

Reputation: 18
  • View blog
  • Posts: 29
  • Joined: 12-October 12

Re: No overload for 'Method' takes 0 arguments

Posted 19 October 2012 - 04:33 PM

In second class in line 14 you call method GetAverage() without any arguments which is not defined in first class.

This post has been edited by lukasz_ltt: 19 October 2012 - 04:34 PM

Was This Post Helpful? 1
  • +
  • -

#3 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5417
  • View blog
  • Posts: 11,608
  • Joined: 02-June 10

Re: No overload for 'Method' takes 0 arguments

Posted 19 October 2012 - 04:35 PM

The method signature requires a parameter of an int array
public int GetAverage(int[] temps)


but you are calling it with no parameter.
Console.WriteLine(weeklyTemps1.GetAverage());

Thus the error is telling you the exact truth.
There are no overloads (versions of the method) that exist taking 0 parameters.
Was This Post Helpful? 1
  • +
  • -

#4 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2233
  • View blog
  • Posts: 9,401
  • Joined: 29-May 08

Re: No overload for 'Method' takes 0 arguments

Posted 19 October 2012 - 04:40 PM

No overload for 'GetAverage' takes 0 arguments


Let decode the error message.
No Overload ...
- What is an Overload?
A multiple methods with the same name but with different input signatures.
So it has something to do with the method "GetAverage"

takes 0 arguments
- What are arguments?
Arguments are the values you provide for a method's input parameters.
  Public Function Add(x As Integer, y As Integer) As Integer
    Return x + y
  End Function
  
  Dim z = Add(1,2)
  

Parameters: x y
Arguments: 1 2

So it must be something to the number of parameters I'm passing, or not passing.

Deciphered
No Overload of the Method "GetAverage" has Zero number of Parameters, to take the Zero number of parameters I'm passing.


Your debugging and analysis skills apply not only to programming! Use them.

This post has been edited by AdamSpeight2008: 19 October 2012 - 04:42 PM

Was This Post Helpful? 3
  • +
  • -

#5 mathanor  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 19-October 12

Re: No overload for 'Method' takes 0 arguments

Posted 19 October 2012 - 05:46 PM

D'oh. Thanks for that. :sweatdrop:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1