Click here to Skip to main content
15,885,869 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am getting multiple "there is no argument that corresponds to the formal parameter errors and I can't figure out why. Most are related to my 'BrewMethod'

Here is the code
<pre>public class CoffeeMaker
{
	public string flavor;
	public string power;
	public string s;
	public string lid;
	public string water;
	public void PowerMethod()
	{ 

		string power = "on";
		Console.WriteLine("Coffee Maker is now on.");
		BrewMethod(power);
		CupMethod(power);
		WaterMethod(power);
		SizeMethod(power);
	}
	public void CupMethod(string power)
	{
		if (power == "on")
		{
			Console.WriteLine("Enter flavor of the pod.");
			string flavor = Console.ReadLine();

			BrewMethod(flavor);
		}
		else
		{
			Console.WriteLine("Please turn on coffee maker");
		}
	}
	
	public void WaterMethod(string power)
	{

		if (power == "on")
		{
			int waterAmount;

			Console.WriteLine("In ounces between 6 and 42, enter the amount of water that will be put in.");
			waterAmount = int.Parse(Console.ReadLine());

			if (waterAmount > 42 || waterAmount < 6)
			{
				Console.WriteLine("Enter a valid amount.");
			}

			else
			{
				string water = "enough";
				BrewMethod(water);
			}
		}
		else
		{
			Console.WriteLine("Please turn on coffee maker");
		}
	}


	public void SizeMethod(string power)
	{ 
		if (power == "on")
		{
			int size;

			Console.WriteLine("What size coffee?");
			Console.WriteLine("- Enter 1 for small");
			Console.WriteLine("- Enter 2 for medium");
			Console.WriteLine("- Enter 3 for large");

			size = int.Parse(Console.ReadLine());


			if (size < 1 || size > 3)
			{
				Console.WriteLine("Enter a valid size.");

			}

			if (size == 1)
			{
				string s = "small";
				BrewMethod(s);
			}

			if (size == 2)
			{
				string s = "medium";
				BrewMethod(s);
			}

			if (size == 3)
			{
				string s = "large";
				BrewMethod(s);
			}
		}
		else
		{
			Console.WriteLine("Please turn on coffee maker.");
		}
	}
		public void LidMethod()
		{
				Console.WriteLine("Lid has been closed.");
				string lid = "closed";
				BrewMethod(lid);
	}

	public void BrewMethod(string power, string flavor, string lid, string s, string water)
	{
		if (power != "on")

		Console.WriteLine("Lid has been closed.");
		
	}

}




What I have tried:

using base but it just throws an 'unexpected character' error and doesn't do anything about the other errors.
Posted
Updated 8-Mar-20 23:11pm

The reason for the error is that the method signature of the BrewMethod states that it expects five string arguments called power, flavour, lid, s and water.

public void BrewMethod(string power, string flavor, string lid, string s, string water)


However when you call the BrewMethod method from other methods you only call it with one argument.

public void PowerMethod()
{
    string power = "on";
    Console.WriteLine("Coffee Maker is now on.");
    BrewMethod(power);    <------ Called with one argument whereas fivearguments are expected
    CupMethod(power);
    WaterMethod(power);
    SizeMethod(power);
}


You must therefore provide the missing arguments to the BrewMethod wherever you call it.
 
Share this answer
 
Comments
Member 14637431 8-Mar-20 15:58pm    
Thanks, fixed my problem! I tried to use the same principle to fix the same error in relation to the 'power' when I called it after the variable name (so public void CupMethod(string Power)) but it's not really working. Any idea how I could fix that?
Tony Hill 8-Mar-20 16:07pm    
Yes but your CupMethod calls the BrewMethod with one argument as doesCupMethod, WaterMethod, SizeMethod, LidMethod.

You have to fix it in all those methods as well.
Member 14637431 8-Mar-20 16:42pm    
can you clarify? I'm kind of confused as to what you mean
Your BrewMethod definition includes four parameters that are not used. Redefine it as:
C#
public void BrewMethod(string power)
{
    if (power != "on")
        Console.WriteLine("Lid has been closed.");    
}


[edit]
However, after looking more closely, you have other methods calling BrewMethod with different value types. That will not work since BrewMethod can only handle a single parameter. You need to change it to handle the different types (try a set of enums), so it will need an enum type and its value. Something like:
C#
enum brewtypes{ power, water, ... etc.};

public void BrewMethod(brewtypes type, string value)
{
    if (type == brewtypes.power && value != "on")
        Console.WriteLine("Lid has been closed.");    
}


[/edit]
 
Share this answer
 
v3

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