11

How can I fix this error?

"No overload for method 'output' takes 0 arguments".

The error is at the very bottom at "fresh.output();".

I don't know what I'm doing wrong. Can someone tell me what I should do to fix the code?

Here is my code:

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

namespace ConsoleApplication_program
{
    public class Numbers
    {
        public double one, two, three, four;
        public virtual void output(double o, double tw, double th, double f)
        {
            one = o;
            two = tw;
            three = th;
            four = f;
        }
    }
    public class IntegerOne : Numbers
    {
        public override void output(double o, double tw, double th, double f)
        {
            Console.WriteLine("First number is {0}, second number is {1}, and third number is {2}", one, two, three);
        }
    }
    public class IntegerTwo : Numbers
    {
        public override void output(double o, double tw, double th, double f)
        {
            Console.WriteLine("Fourth number is {0}", four);
        }
    }
    class program
    {
        static void Main(string[] args)
        {
            Numbers[] chosen = new Numbers[2];

            chosen[0] = new IntegerOne();
            chosen[1] = new IntegerTwo();

            foreach (Numbers fresh in chosen)
            {
                fresh.output();
            }     
            Console.ReadLine();
        }
    }
}
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
User
  • 159
  • 1
  • 3
  • 10

5 Answers5

11

It's telling you that the method "output" needs arguments. Here's the signature for "output":

public override void output(double o, double tw, double th, double f)

So if you want to call that you need to pass in four doubles.

fresh.output(thing1,thing2,thing3,thing4);

Or to use hard coded values as an example:

fresh.output(1,2,3,4);
Bill Gregg
  • 7,067
  • 2
  • 22
  • 39
  • I changed it into this: "fresh.output(double o, double tw, double th, double f);" but I got more errors. Can you please help with that too? – User Oct 22 '13 at 12:47
  • 1
    When you call a method, you pass in instances. You don't have to declare the type again. That is done when you declare the method. You need to understand the difference between calling the method and declaring the method. – Bill Gregg Oct 22 '13 at 12:51
6

There's no method named output that takes 0 arguments, there's only one that accepts 4 arguments. You must pass parameters to output():

foreach (Numbers fresh in chosen)
{
    fresh.output(o, tw, th, f);
}
Chris Mantle
  • 6,595
  • 3
  • 34
  • 48
0

You're calling the output method with 0 (zero) parameters, but you have declared it to receive 4 double values. The compiler doesn't know what it should call, since there is no output method with no parameter.

codeling
  • 11,056
  • 4
  • 42
  • 71
0

All your implementations of method output takes arguments. Supply the arguments and you should be able to compile.

Like this:

fresh.output(1, 2, 3, 4);
Mikael Östberg
  • 16,982
  • 6
  • 61
  • 79
0

fresh.output() expect 2 parameters and you're not providing them

Manoj Naik
  • 386
  • 4
  • 18