function does not take 0 arguments

This is a discussion on function does not take 0 arguments within the C++ Programming forums, part of the General Programming Boards category; Hey I'm trying to compile my program, but I cannot figure out this compile error, I've spent almost 2 hours ...

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    25

    function does not take 0 arguments

    Hey I'm trying to compile my program, but I cannot figure out this compile error, I've spent almost 2 hours now trying to figure it out.

    Heres the code :

    Code:
     # include <iostream>
    
    using namespace std;
    
    void getDate ();
    void printDate (int, int, int );
    int dayNumber (int, int, int);
    bool validDate (int, int, int);
    bool isLeapYear (int);
    
    void main ()
    {
    
      cout << "This program will ask for a date and then return it in a different format" << endl;
      
       getDate ();
    
    
    return ;
    }
    
    void getDate ()
    {
    
      bool valid;
      int month;
      int day;
      int year;
      char slash1;
      char slash2;
      
      
      
      cout << "Please enter the date in the form of mm/dd/yyyy:           "<< endl;
      cin >> month >> slash1 >> day >> slash2 >> year;
    
    
      valid = validDate( month, day, year);  
      
      if (valid == false)
       { 
        cout << " Date is invalid, please enter a year 1 - 3000 only, with a correct month and day in the form of mm/dd/yyyy: " << endl;
        cin >> month >> slash1 >> day >> slash2 >> year;
       }
      
      
      printDate( month, day, year);
    
    
    }
    
    void printDate( int printMonth, int printDay, int printYear)
    {
    
     int daynum; 
    
     switch (printMonth)
     {
      case 1:
    
        cout << printDay << "-January-" << printYear << endl;
    
        break;
    
      case 2:
    
        cout << printDay << "-February-" << printYear << endl;
    
        break;
    
      case 3:
    
        cout << printDay << "-March-" << printYear << endl;
    
        break;
    
      case 4:
    
        cout << printDay << "-April-" << printYear << endl;
    
        break;
    
      case 5:
       
        cout << printDay << "-May-" << printYear << endl;
    
        break;
    
      case 6:
    
        cout << printDay << "-June-" << printYear << endl;
    
        break;
    
      case 7:
    
        cout << printDay << "-July-" << printYear << endl;
    
        break;
    
      case 8:
    
        cout << printDay << "-August-" << printYear << endl;
        break;
    
      case 9:
    
        cout << printDay << "-September-" << printYear << endl;
    
        break;
    
      case 10:
    
        cout << printDay << "-October-" << printYear << endl;
    
        break;
    
      case 11:
    
        cout << printDay << "-November-" << printYear << endl;
     
        break;
    
      case 12:
    
        cout << printDay << "-December-" << printYear << endl;
    
        break;
     }
       
     daynum =  dayNumber( printMonth, printDay, printYear);
      
     cout <<" is day number " << daynum  << " in " << printYear << endl;
    
    }
    
    int dayNumber ( int month, int day, int year )
    {
     int dayNum2;
     int leapDay;
     leapDay = 31;
     bool leapYear;
    
     leapYear = isLeapYear(int year);
    
    if ( leapYear == true)
     leapDay = 32;
    
    
     switch (month)
      {
       case 1:
      
        dayNum2 = day;
      
        break;
    
       case 2:
    
        dayNum2 = leapDay + day;
    
        break;    
    
       case 3:
    
        dayNum2 = 59 + day;
    
        break;
    
       case 4:
    
        dayNum2 = 90 + day;
    
        break;
    
       case 5:
    
        dayNum2 = 120 + day;
    
        break;
    
       case 6:
    
        dayNum2 = 151 + day;
    
        break;
    
       case 7:
    
        dayNum2 = 181 + day;
    
        break;
    
       case 8:
    
        dayNum2 = 212 + day;
    
        break;
    
       case 9:
    
        dayNum2 = 243 + day;
    
        break;
    
       case 10:
    
        dayNum2 = 273 + day;
    
        break;
    
       case 11:
    
        dayNum2 = 304 + day;
    
        break;
    
       case 12:
    
        dayNum2 = 334 + day;
    
        break;
    
     }
    return dayNum2;
    }
    
    bool validDate (int day, int month, int year)
     {
    
      int leapDay;
      leapDay = 28;
      bool leapYear;
    
    leapYear = isLeapYear( int year );
    
    if (leapYear == true)
     leapDay = 29;
    
     if ( year >= 1 & year <= 3000)
    {
        if (month >=1 & month <= 12)
         {
           if (month == 2)
            {
             if (day >= 1 & day <= leapDay)
              return true;
             else
              return false;
            }
           else if ( month == 1 || month == 3 || month == 5 || month == 7 || month  == 8 || month == 10 || month == 12)
            {
             if ( day >= 1 & day <= 31)
              return true;
             else
              return false;
            }
           else
            {
             if ( day >= 1 & day <= 30 )
              return true;
             else
              return false;
            }
           }
        else
         return false;
       }
     else
      return false;
     }        
    
    bool isLeapYear(int year)
     {
    
      if ( year % 100 == 0)
       {
        if ( year % 400 == 0)
         return true;
        else
         return false;
       }
    
      else if ( year % 4 == 0 )
       return true;
      else
      return false;
    
     }
    And heres the error I get-

    syntax error : 'int' should be preceded by ')'

    error C2660: 'isLeapYear' : function does not take 0 arguments

    error C2059: syntax error : ')'

    error C2144: syntax error : 'int' should be preceded by ')'

    error C2660: 'isLeapYear' : function does not take 0 arguments

    error C2059: syntax error : ')'

    I encounter the "function does not take 0 arguments" error before, but it was with void functions, I dont understand why its happening with a bool function.
    Any help would be appreciated and thanks in advance.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You don't use types when you call a function. If you intend to call a function, just use the variable name.

  3. #3
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    BTW, the compiler should give you line numbers of where the errors are. When you're posting code with errors, especially when you have tons of code, it would help if you highlight the lines that are causing the problems. Otherwise, I usually just move on to the next post without even wasting my time looking at it.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  4. #4
    Registered User
    Join Date
    Jul 2008
    Posts
    10
    I think it is how you call IsLeapyear() function. I didn't understand this type of calling IsLeapyear(int year)? according to my knowledge year is sufficiant .
    Last edited by jayee_spicyguy; 10-26-2008 at 04:08 AM.

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,455
    Code:
    bool validDate (int day, int month, int year)
    {
    
    	int leapDay;
    	leapDay = 28;
    	bool leapYear;
    
    	leapYear = isLeapYear( year );
    
    	if (leapYear == true)
    		leapDay = 29;
    
    	if ( year >= 1 & year <= 3000)
    	{
    		if (month >=1 & month <= 12)
    		{
    			if (month == 2)
    			{
    				if (day >= 1 & day <= leapDay)
    					return true;
    				else
    					return false;
    			}
    			else if ( month == 1 || month == 3 || month == 5 || month == 7 || month  == 8 || month == 10 || month == 12)
    			{
    				if ( day >= 1 & day <= 31)
    					return true;
    				else
    					return false;
    			}
    			else
    			{
    				if ( day >= 1 & day <= 30 )
    					return true;
    				else
    					return false;
    			}
    		}
    		else
    			return false;
    	}
    	else
    		return false;
    }
    & is not the symbol for logical AND. It is the symbol for binary AND. You might want to read up on those a bit, because that code will fail to do what you want.

    Code:
    int dayNumber ( int month, int day, int year )
    {
    	int dayNum2;
    	int leapDay;
    	leapDay = 31;
    	bool leapYear;
    
    	leapYear = isLeapYear(year);
    
    	if ( leapYear == true)
    		leapDay = 32;
    
    	switch (month)
    	{
    	case 1:
    		dayNum2 = day;
    		break;
    	case 2:
    		dayNum2 = leapDay + day;
    		break;    
    	case 3:
    		dayNum2 = 59 + day;
    		break;
    	case 4:
    		dayNum2 = 90 + day;
    		break;
    	case 5:
    		dayNum2 = 120 + day;
    		break;
    	case 6:
    		dayNum2 = 151 + day;
    		break;
    	case 7:
    		dayNum2 = 181 + day;
    		break;
    	case 8:
    		dayNum2 = 212 + day;
    		break;
    	case 9:
    		dayNum2 = 243 + day;
    		break;
    	case 10:
    		dayNum2 = 273 + day;
    		break;
    	case 11:
    		dayNum2 = 304 + day;
    		break;
    	case 12:
    		dayNum2 = 334 + day;
    		break;
    	}
    	return dayNum2;
    }
    In this function, you should really initialize dayNum2 or add a default case to avoid compiler warnings about potentially unused variable and to keep your code in check if you get an invalid month.

    Void main should not be used.
    http://cpwiki.sf.net/void_main

    Do not strip the names of the parameters in the function prototypes, either.
    And main must return an integer, or you must remove the return statement altogether.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Code:
     switch (month)
      {
       case 1:
      
        dayNum2 = day;
      
        break;
    
       case 2:
    
        dayNum2 = leapDay + day;
    
        break;    
    
       case 3:
    
        dayNum2 = 59 + day;
    
        break;
    
       case 4:
    
        dayNum2 = 90 + day;
    
        break;
    
       case 5:
    
        dayNum2 = 120 + day;
    
        break;
    
       case 6:
    
        dayNum2 = 151 + day;
    
        break;
    
       case 7:
    
        dayNum2 = 181 + day;
    
        break;
    
       case 8:
    
        dayNum2 = 212 + day;
    
        break;
    
       case 9:
    
        dayNum2 = 243 + day;
    
        break;
    
       case 10:
    
        dayNum2 = 273 + day;
    
        break;
    
       case 11:
    
        dayNum2 = 304 + day;
    
        break;
    
       case 12:
    
        dayNum2 = 334 + day;
    
        break;
    
     }
    could also be written:
    Code:
       switch (month)
      {
       case 12:
        dayNum2 += 30;
       case 11:
        dayNum2 += 31;
       case 10:
        dayNum2 += 30;
       case 9:
        dayNum2 += 31;
       case 8:
        dayNum2 += 31;
       case 7:
        dayNum2 += 30;
       case 6:
        dayNum2 += 31;
       case 5:
        dayNum2 += 30;
       case 4:
        dayNum2 += 31;
       case 3:
        if (leapYear) dayNum2 += 29; 
        else dayNum2 += 28;
       case 2:
        dayNum2 += 31;
       case 1:
        dayNum2  += day;
        break;
     }
    It's not necessarily BETTER this way (it's a tad slower unless the compiler understands what's going on and precalculates the sum), but I think it's clearer to understand what is going on.

    Note that the cases do NOT have a break on purpose, so that they fall through to the next level below, hence they are "back to front".

    The above code has not been tested!

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 02:07 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Help passing arguments to function
    By HAssan in forum C Programming
    Replies: 2
    Last Post: 11-26-2007, 01:15 PM
  4. Arrays as function arguments :(
    By strokebow in forum C Programming
    Replies: 10
    Last Post: 11-18-2006, 02:26 PM
  5. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 06:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21