No Overload for Method error

  • (2 Pages)
  • +
  • 1
  • 2

27 Replies - 5136 Views - Last Post: 30 August 2011 - 12:38 PM Rate Topic: -----

#1 Insanitypress76  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 15
  • Joined: 17-June 11

No Overload for Method error

Posted 30 August 2011 - 11:28 AM

Okay, here goes. I keep getting an error that I can't figure out. I think it has something to do with the constructor class, but my text book is no help and neither is anyone else online so far because, while they list the same errors, their code is so complex I don't understand the solution. I'm sure mine is simple and I just haven't been able to figure it out.

Here's the Error:
Error 1 No overload for method 'DisplayCollectedInfo' takes '0' arguments

Here's the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CIS247_Week_1_Lab_Flaherty
{
    class Program
    {
        public static void Main()
        {
            string name;
            int age;
            double mileage;
          
            DisplayApplicationInformation();

            GetName();

            GetAge();

            GetMileage();

            DisplayCollectedInfo();

            TerminateApplication();

        }
        public static void DisplayApplicationInformation()
        {
            string outputTitle = ("Start Program");
            
            DisplayDivider(ref outputTitle);

            Console.WriteLine("Welcome to the Basic User Interface Program");
            
            Console.WriteLine("CIS247, Week 1 Lab");

            Console.WriteLine("Name: Amanda Flaherty");

            Console.WriteLine("This program accepts user input as a string, then makes the appropriate data conversion.");
                   
           
        }


        public static void DisplayDivider(ref string outputTitle)
        {
            Console.WriteLine();

            Console.WriteLine("******************** " + outputTitle + " ********************");

            Console.WriteLine();
        }
        public static string GetName()
        {
            string outputTitle = ("Get Name");
            
            string name, getInput;
            
            DisplayDivider(ref outputTitle);

            Console.WriteLine();

            Console.Write("Enter your name: ");
            
            getInput = Console.ReadLine();

            Console.WriteLine();

            name = getInput;

            return name;


        }

        public static int GetAge()
        {
            string outputTitle = ("Get Age");

            string getInput;
            
            int age;
            
            DisplayDivider(ref outputTitle);

            Console.WriteLine();

            Console.Write("Enter your age: ");

            getInput = Console.ReadLine();
            
            Console.WriteLine();

            age = Convert.ToInt32(getInput);

            return age;


        }

        public static double GetMileage()
        {
            string outputTitle = ("Get Mileage");
            
            double mileage;
            
            DisplayDivider(ref outputTitle);

            Console.WriteLine();

            Console.Write("Enter the MPG of your car: ");

            mileage = Convert.ToDouble(Console.ReadLine());

            Console.WriteLine();

            return mileage;

        
        }

        public static void DisplayCollectedInfo(ref string name, ref string age, ref string mileage)
        {
            string outputTitle = ("Information Display");

            DisplayDivider(ref outputTitle);

            Console.WriteLine("Your name is " + name + ".");

            Console.WriteLine();
            
            Console.WriteLine("Your age is " + age + ".");

            Console.WriteLine();
            
            Console.WriteLine("Your car's MPG is: " + mileage + ".");

            Console.WriteLine();
        }

        public static void TerminateApplication()
        {
            string outputTitle = ("End Application");
            
            DisplayDivider(ref outputTitle);

            Console.WriteLine("Thank you for using the Basic Uster Interface Program.");

            Console.ReadLine();
        }
    }
}



I just can't get the main method to call the DisplayCollectedInfo method properly. If someone could tell me where I'm going wrong and why, I'd be very grateful.

Is This A Good Question/Topic? 0
  • +

Replies To: No Overload for Method error

#2 CreaturGames  Icon User is offline

  • D.I.C Regular

Reputation: 30
  • View blog
  • Posts: 290
  • Joined: 29-December 09

Re: No Overload for Method error

Posted 30 August 2011 - 11:40 AM

Well, first I will tell you what the error means.

Error	1	No overload for method 'DisplayCollectedInfo' takes '0' arguments



The error means that either the method doesn't exist or it is missing arguments, which are the inputs for the method to be executed within the application. In this case, you forgot 3 arguments to input in, which are name, age, and mileage.

I'll try to fix it, unless you want to fix it yourself. :)

DisplayCollectedInfo(name, age, mileage);

EDIT: Fixed the code:

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

namespace CIS247_Week_1_Lab_Flaherty
{
    class Program
    {
        static string name = "";
        static int age = 0;
        static double mileage = 0;
        public static void Main()
        {
          
            DisplayApplicationInformation();

            GetName();

            GetAge();

            GetMileage();

            DisplayCollectedInfo(name, age.ToString(), mileage.ToString());

            TerminateApplication();

        }
        public static void DisplayApplicationInformation()
        {
            string outputTitle = ("Start Program");
            
            DisplayDivider(ref outputTitle);

            Console.WriteLine("Welcome to the Basic User Interface Program");
            
            Console.WriteLine("CIS247, Week 1 Lab");

            Console.WriteLine("Name: Amanda Flaherty");

            Console.WriteLine("This program accepts user input as a string, then makes the appropriate data conversion.");
                   
           
        }


        public static void DisplayDivider(ref string outputTitle)
        {
            Console.WriteLine();

            Console.WriteLine("******************** " + outputTitle + " ********************");

            Console.WriteLine();
        }
        public static string GetName()
        {
            string outputTitle = ("Get Name");
            
            
            
            DisplayDivider(ref outputTitle);

            Console.WriteLine();

            Console.Write("Enter your name: ");
            
            string getInput = Console.ReadLine();

            Console.WriteLine();

            name = getInput;

            return name;


        }

        public static int GetAge()
        {
            string outputTitle = ("Get Age");

            string getInput;
            
            DisplayDivider(ref outputTitle);

            Console.WriteLine();

            Console.Write("Enter your age: ");

            getInput = Console.ReadLine();
            
            Console.WriteLine();

            age = Convert.ToInt32(getInput);

            return age;


        }

        public static double GetMileage()
        {
            string outputTitle = ("Get Mileage");
            
            DisplayDivider(ref outputTitle);

            Console.WriteLine();

            Console.Write("Enter the MPG of your car: ");

            mileage = Convert.ToDouble(Console.ReadLine());

            Console.WriteLine();

            return mileage;

        
        }

        public static void DisplayCollectedInfo(string name, string age, string mileage)
        {
            string outputTitle = ("Information Display");

            DisplayDivider(ref outputTitle);

            Console.WriteLine("Your name is " + name + ".");

            Console.WriteLine();
            
            Console.WriteLine("Your age is " + age + ".");

            Console.WriteLine();
            
            Console.WriteLine("Your car's MPG is: " + mileage + ".");

            Console.WriteLine();
        }

        public static void TerminateApplication()
        {
            string outputTitle = ("End Application");
            
            DisplayDivider(ref outputTitle);

            Console.WriteLine("Thank you for using the Basic Uster Interface Program.");

            Console.ReadLine();
        }
    }
}


Here it is. Either you can use the code to fix your application, or just replace your old code with this code.

This post has been edited by CreaturGames: 30 August 2011 - 11:50 AM

Was This Post Helpful? 1
  • +
  • -

#3 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9055
  • View blog
  • Posts: 33,990
  • Joined: 12-June 08

Re: No Overload for Method error

Posted 30 August 2011 - 11:44 AM

Read the error.

Quote

No overload for method 'DisplayCollectedInfo' takes '0' arguments


The compiler cannot find a method called "DisplayCollectedInfo" that has zero arguments. That would push the assumption that you need to fill in parameters for DisplayCollectedInfo. I would suggest checking out the intellisense or possibly revisiting where you have "DisplayCollectedInfo" to see how many parameters (and what types) are acceptable.
Was This Post Helpful? 1
  • +
  • -

#4 Insanitypress76  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 15
  • Joined: 17-June 11

Re: No Overload for Method error

Posted 30 August 2011 - 11:50 AM

View PostCreaturGames, on 30 August 2011 - 11:40 AM, said:

Well, first I will tell you what the error means.

Error	1	No overload for method 'DisplayCollectedInfo' takes '0' arguments



The error means that either the method doesn't exist or it is missing arguments, which are the inputs for the method to be executed within the application. In this case, you forgot 3 arguments to input in, which are name, age, and mileage.

I'll try to fix it, unless you want to fix it yourself. :)

DisplayCollectedInfo(name, age, mileage);


Okay, I forgot to mention I've tired these:

DisplayCollectedInfo(name, age, mileage); ----> Error received: The best overloaded method match for 'Program.DisplayCollectedInfo(ref string, ref string, ref string)' has some invalid arguments (plus an argument must be passed with ref for each of the three variables)

DisplayCollectedInfo(string name, int age, double mileage); ------> this one gets a bunch of "invalid terms" and "; expected"

DisplayCollectedInfo(ref name, ref age, ref mileage); -----> Error received: Error 1 The best overloaded method match for 'Program.DisplayCollectedInfo(ref string, ref string, ref string)' has some invalid arguments (each variable also receives a cannot convert from/to error)

DisplayCollectedInfor(ref string name, ref int age, ref double mileage); ------> Again, a bunch of "invalid expression" and "; expected" and "invalid term"
Was This Post Helpful? 0
  • +
  • -

#5 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1252
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: No Overload for Method error

Posted 30 August 2011 - 11:52 AM

Check this out:

public static void DisplayCollectedInfo(ref string name, ref string age, ref string mileage)


Notice how you're telling that method, "Man, you're going to recieve these three things to work with. Just wait for 'em to come then do your thing."

But then, when you call on the method:

DisplayCollectedInfo();


You're not giving the method the three things you promised you would. You're a liar and you broke your methods heart. In retaliation your compiler is giving you a nasty beating.

Make things right, keep your promises. Give that method what you owe it. :)

Edit: You ninja poster, you.

Read about ref argument passing here. It's pretty easy. If you still need help, let us know by pasting the exact code you are running and the exact error message your getting.

Don't paraphrase. Copy and paste it here for us to read and analyze.

This post has been edited by Sergio Tapia: 30 August 2011 - 11:54 AM

Was This Post Helpful? 1
  • +
  • -

#6 Insanitypress76  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 15
  • Joined: 17-June 11

Re: No Overload for Method error

Posted 30 August 2011 - 11:54 AM

View PostSergio Tapia, on 30 August 2011 - 11:52 AM, said:

Check this out:

public static void DisplayCollectedInfo(ref string name, ref string age, ref string mileage)


Notice how you're telling that method, "Man, you're going to recieve these three things to work with. Just wait for 'em to come then do your thing."

But then, when you call on the method:

DisplayCollectedInfo();


You're not giving the method the three things you promised you would. You're a liar and you broke your methods heart. In retaliation you compiler is giving you a nasty beating.

Make things right, keep your promises. Give that method what you owe it. :)




See Above, I just listed everything I've tried and the subsequent errors.
Was This Post Helpful? 0
  • +
  • -

#7 CreaturGames  Icon User is offline

  • D.I.C Regular

Reputation: 30
  • View blog
  • Posts: 290
  • Joined: 29-December 09

Re: No Overload for Method error

Posted 30 August 2011 - 11:55 AM

View PostSergio Tapia, on 30 August 2011 - 12:52 PM, said:

Check this out:

public static void DisplayCollectedInfo(ref string name, ref string age, ref string mileage)


Notice how you're telling that method, "Man, you're going to recieve these three things to work with. Just wait for 'em to come then do your thing."

But then, when you call on the method:

DisplayCollectedInfo();


You're not giving the method the three things you promised you would. You're a liar and you broke your methods heart. In retaliation you compiler is giving you a nasty beating.

Make things right, keep your promises. Give that method what you owe it. :)

I laughed at this. This is the funniest, or funnier, way to say what I said. :)

But, as Sergio and I said, if you give the method arguments, you need at least give the method back the right type of arguments.
Was This Post Helpful? 1
  • +
  • -

#8 Insanitypress76  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 15
  • Joined: 17-June 11

Re: No Overload for Method error

Posted 30 August 2011 - 11:57 AM

View PostCreaturGames, on 30 August 2011 - 11:40 AM, said:

Spoiler

Oh! Now that makes some sense. Thanks so much. I'll go try that right now. I probably wouldn't be having this issue, but it's been 8 weeks since my last C# class and this code is supposed to be a review. The cannot convert was causing issues and that's probably why!

This post has been edited by Curtis Rutland: 30 August 2011 - 12:29 PM
Reason for edit:: added spoiler

Was This Post Helpful? 0
  • +
  • -

#9 CreaturGames  Icon User is offline

  • D.I.C Regular

Reputation: 30
  • View blog
  • Posts: 290
  • Joined: 29-December 09

Re: No Overload for Method error

Posted 30 August 2011 - 11:58 AM

Also you need to change 'ref string' to 'string' for each 'ref string'. 'ref string' and 'string' aren't the same. This should fix your code.

EDIT:

public static void DisplayCollectedInfo(string name,  string age, string mileage)


This post has been edited by CreaturGames: 30 August 2011 - 12:00 PM

Was This Post Helpful? 1
  • +
  • -

#10 Insanitypress76  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 15
  • Joined: 17-June 11

Re: No Overload for Method error

Posted 30 August 2011 - 12:01 PM

View PostCreaturGames, on 30 August 2011 - 11:58 AM, said:

Also you need to change 'ref string' to 'string' for each 'ref string'. 'ref string' and 'string' aren't the same. This should fix your code.



Except I get "Invalid expression term 'string'" and "; expected" when I try using
DisplayCollectedInfor(string name, string age.ToString, string mileage.ToString)


and invalid arguments when trying to do the above sans the "string" part.

This post has been edited by Insanitypress76: 30 August 2011 - 12:01 PM

Was This Post Helpful? 0
  • +
  • -

#11 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1252
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: No Overload for Method error

Posted 30 August 2011 - 12:03 PM

I'm afraid you can't use the .ToString() METHOD inside of a parameter list. :(
Was This Post Helpful? 1
  • +
  • -

#12 CreaturGames  Icon User is offline

  • D.I.C Regular

Reputation: 30
  • View blog
  • Posts: 290
  • Joined: 29-December 09

Re: No Overload for Method error

Posted 30 August 2011 - 12:08 PM

View PostSergio Tapia, on 30 August 2011 - 01:03 PM, said:

I'm afraid you can't use the .ToString() METHOD inside of a parameter list. :(

I did it with no problem. That is weird.

Wait. I know you can't use .ToString() in defining methods. I meant to use .ToString() when you are putting in the input of the method:

DisplayCollectedInfo(name, age.ToString(), mileage.ToString());



For defining the method, use this code:
public static void DisplayCollectedInfo( string name,  string age, string mileage)



Sorry for not clarifying.
Was This Post Helpful? 1
  • +
  • -

#13 Insanitypress76  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 15
  • Joined: 17-June 11

Re: No Overload for Method error

Posted 30 August 2011 - 12:10 PM

View PostSergio Tapia, on 30 August 2011 - 12:03 PM, said:

I'm afraid you can't use the .ToString() METHOD inside of a parameter list. :(

Yeah I took that out. I still can't pass name, age and mileage along with the DisplayCollectedInfo() no matter how I try to call it. I've tried everything suggest and some things that weren't. I even took out the convert.toint32 and convert.todouble for age and mileage and just left them as all strings.
Was This Post Helpful? 0
  • +
  • -

#14 CreaturGames  Icon User is offline

  • D.I.C Regular

Reputation: 30
  • View blog
  • Posts: 290
  • Joined: 29-December 09

Re: No Overload for Method error

Posted 30 August 2011 - 12:11 PM

Look at the post above yours. That should fix the error. Sorry if I wasn't clear.
Was This Post Helpful? 1
  • +
  • -

#15 Insanitypress76  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 15
  • Joined: 17-June 11

Re: No Overload for Method error

Posted 30 August 2011 - 12:13 PM

View PostCreaturGames, on 30 August 2011 - 12:11 PM, said:

Look at the post above yours. That should fix the error. Sorry if I wasn't clear.



Nope, it doesn't. Now I get either name, age and mileage don't exist in the current whatever or use of unassigned variables. It still refuses to reference variables no in the main method when calling the method.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2