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



LinkBack URL
About LinkBacks


