Build errors in my code CS1501

No overload for method 'daysOfMonthSwitch' takes '0' a

Page 1 of 1

2 Replies - 1054 Views - Last Post: 07 July 2009 - 05:14 PM Rate Topic: -----

#1 rapunzel2779  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 07-July 09

Build errors in my code CS1501

Post icon  Posted 07 July 2009 - 04:14 PM

Hello. This is homework and I am having difficulty with my build errors. In my main method, I get the errors:

error CS1501: No overload for method 'daysOfMonthSwitch' takes '0' arguments
and
error CS1501: No overload for method 'daysOfMonthIf' takes '0' arguments

I am unable to figure out how to fix these. Is someone able to give me a hand?


using System;

namespace IfSwitch
{
	
	class IfSwitch
	{
		
		[STAThread]

		static int daysOfMonthIf(int month)
		{
		 if (month == 1)
			 Console.WriteLine("Using if statements, month number " + month + "has 31 days");
		 else if (month == 2)
				Console.WriteLine("Using if statements, month number " + month + "has 28 days");
		 else if (month == 3)
			 Console.WriteLine("Using if statements, month number " + month + "has 31 days");
		 else if (month == 4)
			 Console.WriteLine("Using if statements, month number " + month + "has 30 days");
		 else if (month == 5)
			 Console.WriteLine("Using if statements, month number " + month + "has 31 days");
		 else if (month == 6)
			 Console.WriteLine("Using if statements, month number " + month + "has 30 days");
		 else if (month == 7)
			 Console.WriteLine("Using if statements, month number " + month + "has 31 days");
		 else if (month == 8)
			 Console.WriteLine("Using if statements, month number " + month + "has 31 days");
		 else if (month == 9)
			 Console.WriteLine("Using if statements, month number " + month + "has 30 days");
		 else if (month == 10)
			 Console.WriteLine("Using if statements, month number " + month + "has 31 days");
		 else if (month == 11)
			 Console.WriteLine("Using if statements, month number " + month + "has 30 days");
		 else if (month == 12)
			 Console.WriteLine("Using if statements, month number " + month + "has 31 days");
		return month;

		}

		static int daysOfMonthSwitch(int month)
		{
			switch (month)
			{
				case 1:
				case 3:
				case 5:
				case 7:
				case 8:
				case 10:
				case 12: Console.WriteLine("Using switch statements, month number " + month + "has 31 days");
					break;
				case 2: Console.WriteLine("Using switch statements, month number " + month + "has 28 days");
					break;
				case 4:
				case 6:
				case 9:
				case 11: Console.WriteLine("Using switch statements, month number " + month + "has 30 days");
					break;
				default: Console.WriteLine("Invalid month!");
					break;

			}
				 return month;
		
		}


		static void Main(string[] args)
		{
			String Month;
			Console.WriteLine("Please enter the month NUMBER (Jan = 1): ");
			Console.WriteLine();
			Month = Console.ReadLine();
			int month = Convert.ToInt32(Month);

			int methodIf;
			int methodSwitch;
			methodIf = daysOfMonthIf();
			methodSwitch = daysOfMonthSwitch();


		}
	}
}


Is This A Good Question/Topic? 0
  • +

Replies To: Build errors in my code CS1501

#2 Renagado  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 117
  • View blog
  • Posts: 388
  • Joined: 14-June 09

Re: Build errors in my code CS1501

Posted 07 July 2009 - 04:29 PM

You need to pass a int value to those methods, for example
methodIf = daysOfMonthIf(5);


The trick is to look at how you declared those methods:
static int daysOfMonthIf(int month)

clearly shows it needs to have a argument.
And it's the same for the other one.

Edit: Just noticed you also read from the console, so instead of the random 5 I suggested before, pass the int variable month you used.
methodIf = daysOfMonthIf(month);


Just another hint, you don't need two month variables, you can change the last bit of your program to:

static void Main(string[] args)
		{
			
			Console.WriteLine("Please enter the month NUMBER (Jan = 1): ");
			Console.WriteLine();
			int Month = Convert.ToInt32(Console.ReadLine());
			 

			int methodIf;
			int methodSwitch;
			methodIf = daysOfMonthIf(Month);
			methodSwitch = daysOfMonthSwitch(Month);


		}

See what's happening here?

This post has been edited by Renagado: 07 July 2009 - 04:40 PM

Was This Post Helpful? 0
  • +
  • -

#3 rapunzel2779  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 07-July 09

Re: Build errors in my code CS1501

Posted 07 July 2009 - 05:14 PM

Thank you SO much! It worked! I really appreciate this. I am trying so hard to score well in this course.

You're my Hero!!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1