Thread: undeclared indentifier error

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    49

    undeclared indentifier error

    I am writting a program for my programming class. Basiclly its an ATM machine. But I keep getting this error.....

    F:\atm.cpp(40) : error C2065: 'prnt_acct_msg' : undeclared identifier
    F:\atm.cpp(41) : error C2065: 'tans_amt' : undeclared identifier
    F:\atm.cpp(50) : error C2065: 'check_depoist' : undeclared identifier


    here are the lines of the program..
    Code:
    case 1:                                                    // Deposit
                    while ((acct_type !=1) && (acct_type !=2))
                    {
                          print_msg(2) ;                                  // choose account
                          acct_type = choose_acct(acct_type);
                          prnt_acct_msg(acct_type);
                          trans_amt= trans_amt(tans_amt);
                          //cout << "trans_amt = %f\n", trans_amt;
                          printf ("acct_type = %d\n", acct_type);
                          if (acct_type == 1)
                          {
                             save_bal = save_deposit(save_bal, trans_amt);
                             // cout << "save_bal = %f\n", save_bal;
                             }
                          else
                          check_bal = check_depoist(check_deposit, trans_amt);
                          // cout << "check_bal = %f\n", check_bal;
                          printf (" WENT TO ELSE\n");

    Thanks in advance
    Code this

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    So were are those function declared then?

    Oh, hang on, what's this:
    >>trans_amt= trans_amt(tans_amt);
    I think the parameter variable is spelt incorrectly. And you can't name a variable the same as a function and expect to use it.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    It usually means
    - you haven't written the function in question
    - you've written it in a different module, but didn't compile it
    - you spelled it wrong somewhere along the line
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Sep 2003
    Posts
    49
    ignore this...
    >>trans_amt= trans_amt(tans_amt);


    here is where there are declared..
    Code:
    float trans_amount(float);
    float save_deposit(float, float);
    float check_deposit(float, float);
    float save_withd(float, float);
    float check_withd(float, float);
    void print_msg(int);
    int choose_acct(int);
    void print_acct_msg(int);
    	
    
    
    int main(int argc, char *argv[])
    {
    Code this

  5. #5
    Registered User
    Join Date
    Sep 2003
    Posts
    49
    figured it out...spelled wrong doh!

    but now I have a new problem...

    F:\atm.cpp(41) : error C2064: term does not evaluate to a function
    F:\atm.cpp(50) : error C2664: 'check_deposit' : cannot convert parameter 1 from 'float (float,float)' to 'float'
    Context does not allow for disambiguation of overloaded function
    Error executing cl.exe

    any suggestions to translating this to english?
    Code this

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>term does not evaluate to a function
    Probably means you're using a variable name where you should be using a function name.

    >>'check_deposit' : cannot convert parameter 1 from 'float (float,float)' to 'float'
    ... means you are passing a function pointer as a parameter that is supposed to be a variable of type float.

    Again, I reckon this is because you have either have a typo, or your variable and function names are conflicting. Try naming your functions to be obviously different from your variables until you get more used to the language.

    All in all, it's pretty hard to help someone with their code when they don't post any for us to see. So next time, you know what to do, eh?!


    [edit]
    And what language are you writing in? Your filename and probably compiler think your writing C++.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  7. #7
    Registered User
    Join Date
    Sep 2003
    Posts
    49
    its in C

    here is my program...rather long for a post..that's why I didnt post it.

    Thanks for you help

    Code:
    #include <iostream.h>
    #include <stdlib.h>
    #include <stdio.h>
    
    float trans_amount(float);
    float save_deposit(float, float);
    float check_deposit(float, float);
    float save_withd(float, float);
    float check_withd(float, float);
    void print_msg(int);
    int choose_acct(int);
    void print_acct_msg(int);
    	
    
    
    int main(int argc, char *argv[])
    {
    
        int option;
        int acct_type;
        float trans_amt;
        float save_bal =200.00;
        float check_bal= 500.00;
    
        printf("Project 3  ATM machine \n\n");
    
        while (option != 5) {
    
              print_msg(1);                                               // function call print_msg
              scanf("%d", option);
    
    
              switch (option)
              {
               case 1:                                                    // Deposit
                    while ((acct_type !=1) && (acct_type !=2))
                    {
                          print_msg(2) ;                                  // choose account
                          acct_type = choose_acct(acct_type);
                          print_acct_msg(acct_type);
                          trans_amt = trans_amt(trans_amt);
                          //cout << "trans_amt = %f\n", trans_amt;
                          printf ("acct_type = %d\n", acct_type);
                          if (acct_type == 1)
                          {
                             save_bal = save_deposit(save_bal, trans_amt);
                             // cout << "save_bal = %f\n", save_bal;
                             }
                          else
                          check_bal = check_deposit(check_deposit, trans_amt);
                          // cout << "check_bal = %f\n", check_bal;
                          printf (" WENT TO ELSE\n");
    
                          }
    
                          acct_type=0;
                          break;
    
    
                case 2: // Withdrawal
                     while ((acct_type !=1) && (acct_type !=2))
                     {
                           print_msg(3);
                           acct_type = choose_acct(acct_type);
                           print_acct_msg(acct_type);
                           trans_amt = trans_amount(trans_amt);
                           printf ("acct_type = %d \n", acct_type);
                           if (acct_type == 1)
                           {
                            save_bal = save_withd(save_bal, trans_amt);
    
                            }
                           else
                           {
                            check_bal = check_withd(check_bal, trans_amt);
                            printf ("check_bal = %f \n", check_bal);
                            printf ("went to else");
                            }
    
                            }
    
                        case 3: // transfer funds
                             print_msg(4);
                             printf ("Which account do you want to transfer from?\n");
                             print_msg(8); // prints the account menu type
                             printf ("Transfet to which account? \n");
                             print_msg(8);
                             trans_amt = trans_amount(trans_amt);
                             break;
    
                         case 4: // account balances
                              while ((acct_type !=1) && (acct_type != 2))
                              {
                               print_msg(2); // account choices
                               acct_type = choose_acct(acct_type);
                               print_acct_msg(acct_type);
                               }
    
                               acct_type =0;
    
                               break;
    
                          case 5: // end of service
                               print_msg(6);
                               break;
    
    
                          default: // Error
                                   print_msg(7);
                                   break;
                                   }// end of switch(option)
                                   }// end of while (option !=5)
    
              printf (" End of Project3 \n\n");
              return 0;
    
    
          } // end of main
    
    
    void print_msg(int msg_num)
    {
     switch(msg_num)
     {
     case 1: // prints main
     printf ("DEPOSIT FUNDS enter 1\n\n");
     printf ("Withdraw FUNDS enter 2 \n\n");
     printf ("Transfer FUNDS enter 3 \n\n");
     printf ("Accoutn Balances enter 4 \n\n");
     printf ("To end all transactions enter 5 \n\n");
     break;
    
     case 2:
     printf ("Deposit funds \n\n");
          break;
     case 3:
     printf ("Withdrawal funds \n\n");
          break;
     case 4:
     printf ("Transfer funds \n\n");
          break;
     case 5:													//line 140
     printf ("Account Balances\n\n");
          break;
     case 6:
     printf ("End all transactions\n\n");
          break;
     case 7:
     printf ("** Error Please make another selection ** \n\n");
          break;
     case 8:
     printf ("for Savings enter 1\n\n");
     printf ("for Checking enter 2\n\n");
           break;
     case 9:
     printf ("Enter transaction amount \n\n");
          break;
     case 10:
     printf ("Savings \n\n");
          break;
     case 11:
     printf ("Checking \n\n");
          break;
    
          } // end of switch(msg_num)
          return;
          } // end of function print_msg
    
    int choose_acct(int atype)
    {
     print_msg(8);
     scanf("%d", atype);
     return (atype);
     }
    
    void print_acct_msg(int atype)
    {
     printf ("%d \n", atype);
     switch (atype)
     {
     case 1:
     printf ("Savings");
     break;
     case 2:
     printf ("Checking");
     break;
     default:
     print_msg(7);
     break;
    
     } // end of switch
     return ;
     } // end of prnt_acct_msg
    
     float trans_amount(float t_amt)
     {
     print_msg(9);
     scanf("%f", &t_amt);
     printf ("t_amt = %f \n", t_amt);
     return (t_amt);
     }
    
     float save_deposit(float sbalance, float tamount)
     {
      float new_balance;
      new_balance = sbalance + tamount;
      sbalance = new_balance;
      printf ("new_balance = %f \n", new_balance);
      return (sbalance);
      }
    
      float check_deposit (float cbalance, float tamount)
      {
       float new_balance;
       new_balance = cbalance + tamount;
       cbalance = new_balance;
       printf ( "new_balance = %f\n", new_balance);
       return (cbalance);
       }
    
      float save_withd (float sbalance, float tamount)
      {
       float new_balance;
       if (sbalance >= tamount)
       {
        new_balance = sbalance - tamount;
        sbalance = new_balance;
        printf ("new_balance = %f\n", new_balance);
        }
       else
       {
        printf ("Insufficient Funds\n");
        }
        return (sbalance);
        } // end of function save_withd
    
        float check_withd (float cbalance, float tamount)
        {
        float new_balance;
        if (cbalance >= tamount)
        {
         new_balance = cbalance - tamount;
         cbalance = new_balance;
         printf ("new_balance = %f\n", new_balance);
         }
         else
         {
         printf ("Insufficient Funds\n");
         }
         return (cbalance);
         } // end of function check_withd
    Code this

  8. #8
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>its in C
    No it's not. Its C++. This is defined by your .cpp file extension, and your use of the iostream header.

    >>trans_amt = trans_amt(trans_amt);
    You still have that in there? trans_amt is variable not a function.

    >>check_bal = check_deposit(check_deposit, trans_amt);
    Did you mean this instead:
    >>check_bal = check_deposit(check_bal, trans_amt);
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  3. using c++ in c code
    By hannibar in forum C Programming
    Replies: 17
    Last Post: 10-28-2005, 09:09 PM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM