C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 11-24-2003, 04:51 PM   #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
SpEkTrE is offline   Reply With Quote
Old 11-24-2003, 05:01 PM   #2
...
 
kermit's Avatar
 
Join Date: Jan 2003
Posts: 1,190
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
__________________
Got Ed?

sys-sizes
kermit is offline   Reply With Quote
Old 11-24-2003, 05:50 PM   #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
SpEkTrE is offline   Reply With Quote
Old 11-24-2003, 05:58 PM   #4
End Of Line
 
Hammer's Avatar
 
Join Date: Apr 2002
Posts: 6,240
>>#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]
Hammer is offline   Reply With Quote
Old 11-24-2003, 06:03 PM   #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
SpEkTrE is offline   Reply With Quote
Old 11-24-2003, 06:16 PM   #6
End Of Line
 
Hammer's Avatar
 
Join Date: Apr 2002
Posts: 6,240
... 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]
Hammer is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Issue with program that's calling a function and has a loop tigerfansince84 C++ Programming 9 11-12-2008 01:38 PM
Need help with a program, theres something in it for you engstudent363 C Programming 1 02-29-2008 01:41 PM
This is a simple program.. Help me please I think it has an error.. lesrhac03 C Programming 4 02-21-2008 10:39 AM
My program, anyhelp @licomb C Programming 14 08-14-2001 10:04 PM


All times are GMT -6. The time now is 09:20 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

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