error in program????

This is a discussion on error in program???? within the C Programming forums, part of the General Programming Boards category; I am writting this program for my class (basic ATM machine). It compiles and builds with no errors, but when ...

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

    error in program????

    I am writting this program for my class (basic ATM machine). It compiles and builds with no errors, but when I run it, I get an error just after the first screen, where I enter the choice (1-5)

    Any help would be greatful

    here is the error:

    The instruction at "0x00402978" referenced memory at "0x0000000". The memory could not be written.


    and here is the program

    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);
                          
                          /
                          printf ("acct_type = %d\n", acct_type);
                          if (acct_type == 1)
                          {
                             save_bal = save_deposit(save_bal, trans_amt);
                             
                             }
                          else
                          check_bal = check_deposit(check_bal, trans_amt);
                          
                          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

  2. #2
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,528
    You have a stray '/' on line 41 to start

    and after I fixed that, I got these warnings:

    spectre.c: In function `main':
    spectre.c:29: warning: format argument is not a pointer (arg 2)
    spectre.c: In function `choose_acct':
    spectre.c:170: warning: format argument is not a pointer (arg 2)


    Now my supper is waiting, so good luck

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

    Question

    Took care of the stray...but them I still have the same error as before

    Code this

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>#include <iostream.h>
    This is for C++ only. What language are you writing in?

    >>scanf("%d", option);
    Should be
    >>scanf("%d", &option);

    >>scanf("%d", atype);
    should be
    >>scanf("%d", &atype);

    Also, from my compiler:
    Code:
    Possible use of 'option' before definition in function main
    Possible use of 'acct_type' before definition in function main
    Possible use of 'trans_amt' before definition in function main
    If you're still having trouble, post your latest code and the compiler error messages.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Registered User
    Join Date
    Sep 2003
    Posts
    49
    I'm an idiot...
    Thanks hammer, I didnt include the & in the scanf's


    and the iostream was a typo..

    THANKS
    Code this

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    ... and you fixed the other used " before definition" errors as well, right?
    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. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 12:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 12:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 09:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

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