Forbids Declaration with No Type

This is a discussion on Forbids Declaration with No Type within the C++ Programming forums, part of the General Programming Boards category; I'm having a problem with these functions... Code: #include <iomanip.h> #include <stdlib.h> Dep(float Bal, float Amount) { Bal=Bal+Amount; return 0;} ...

  1. #1
    Registered User ProgrammingDlux's Avatar
    Join Date
    Jan 2002
    Posts
    86

    Forbids Declaration with No Type

    I'm having a problem with these functions...

    Code:
    #include <iomanip.h>
    #include <stdlib.h>
    
    Dep(float Bal, float Amount)
         { Bal=Bal+Amount;
           return 0;}
    
    Check(float Bal, float Amount)
         { Bal=Bal-Amount;
           return 0;}
    
    Charge(float Bal, float Amount)
         { Bal=Bal-Amount;
           return 0;}
    
    Withdraw(float Bal, float Amount)
         { Bal=Bal-Amount;
           return 0;}
    
    
    main()
     {  float Bal, Amount; char Comm;
    
    
        cout<<"\n BALANCING CHECKBOOK PROGRAM ";
        cout<<"\n --------------------------- ";
        cout<<"\n\n Christian Aziz' Account ";
        cout<<"\n Enter Starting Balance : "; cin>>Bal;
        cout<<"\n Command Options: "
            <<"\n d- deposit"
            <<"\n c- check "
            <<"\n s- service charge "
            <<"\n w- withdrawal "
            <<"\n x- exit "<<endl;
        cout<<"\n Enter command: "; cin>>Comm;
        cout<<"\n Enter amount in dollars and cents: "; cin>>Amount;
         while(Comm)
           {
                  if(Comm == 'd')
                  {Dep(Bal, Amount);}
             else if(Comm == 'c')
                  {Check(Bal,Amount);}
             else if(Comm == 's')
                  {Charge(Bal,Amount);}
             else if(Comm == 'w')
                  {Withdraw(Bal,Amount);}
             else if(Comm == 'x')
                  {cout<<"\n Your New Balance is: $"<<Bal; break;}
             else
                  {continue;}
             cout<<"\n Enter another command: "; cin>>Comm;
             cout<<"\n Enter amount in dollars and cents: "; cin>>Amount;
    
           }
    
          system("PAUSE");
          return 0;
    }
    ...I get 4 errors
    ANSI C++ forbids declaration 'Dep' with no type
    ANSI C++ forbids declaration 'Check' with no type
    ANSI C++ forbids declaration 'Charge' with no type
    ANSI C++ forbids declaration 'Withdrawal' with no type

    What am I doing wrong??
    "For in fact what is a man in Nature? A Nothing in comparison with the Infinite, an All in comparison with the Nothing, a mean between nothing and everything"- Blaise Pascal

  2. #2
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    You need to declare the return type of those functions. In the case you are showing, you would precede the function names with int.

    int withdrawl(params)
    {code};

  3. #3
    Registered User ProgrammingDlux's Avatar
    Join Date
    Jan 2002
    Posts
    86
    I'm not sure I understand..do I do that in the Function Header or the Function Call Statement?
    "For in fact what is a man in Nature? A Nothing in comparison with the Infinite, an All in comparison with the Nothing, a mean between nothing and everything"- Blaise Pascal

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    When you declare and define your functions, you specify a return type. When you actually call the function all you need to do is write the name of the function and the parameters that you want to pass to it.

    -Prelude
    My best code is written with the delete key.

  5. #5
    Registered User ProgrammingDlux's Avatar
    Join Date
    Jan 2002
    Posts
    86
    excuse my ignorance, but I've been working on this for almost the whole day (whether i should have or not), my eyes are blurry, and I'm frustrated..Exactly how would I implement this return type into the program so I get SUCCESS when compiled?
    "For in fact what is a man in Nature? A Nothing in comparison with the Infinite, an All in comparison with the Nothing, a mean between nothing and everything"- Blaise Pascal

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Code:
    #include <iostream>
    using namespace std;
    
    int function ( int i )
    {
      return i * 2;
    }
    
    int main ( void )
    {
      int data = 10, ret;
      ret = function ( data );
      cout<< ret <<endl;
      return EXIT_SUCCESS;
    }
    -Prelude
    My best code is written with the delete key.

  7. #7
    Registered User ProgrammingDlux's Avatar
    Join Date
    Jan 2002
    Posts
    86

    Thumbs up

    AHHH ::smacks himself on the forehead:: Once again, Prelude..thanks a lot!!
    "For in fact what is a man in Nature? A Nothing in comparison with the Infinite, an All in comparison with the Nothing, a mean between nothing and everything"- Blaise Pascal

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  2. Errors with including winsock 2 lib
    By gamingdl'er in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2005, 07:13 PM
  3. Question on l-values.
    By Hulag in forum C++ Programming
    Replies: 6
    Last Post: 10-13-2005, 04:33 PM
  4. ISO C++ forbids declaration of
    By bhorrobi in forum C++ Programming
    Replies: 4
    Last Post: 10-31-2003, 02:36 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM

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