Jump to content

A little ATM Help :D

- - - - -

  • Please log in to reply
2 replies to this topic

#1
teensicle

teensicle

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
So i got an assignment to try and write a simple ATM program which shouldn't take long however ive hit a little snag... the problem that i am experiencing is when the program executes the if statement and i purposely enter a withdraw amount greater than 100 which i set when i select Y to go back to the main menu it goes back to the main however it then ends the program. This is my code below that i already started (feel free to critique :))...




#include <stdio.h>
#include <stdlib.h>
#include <conio.h>






int cash_withdrawls(w_amount);


int w_amount;
int c_bal = 100;




int main(void)
{


    char selection;


        printf("Welcome to BANK-AT-HOME's ATM System\n\n");
        printf("Please select from the menu below\n");
        printf("A. Cash Withdrawls\n");
        printf("L. Lodgements\n");
        printf("B. Balance Check\n");
        printf("P. Bill Payment\n");
        printf("C. Credit Purchase\n");
        printf("E. Exit\n");
            scanf("%c", &selection);




    switch (selection) {
        case 'A':
        case 'a':
        system("CLS");
        cash_withdrawls() ;
        break;


        case 'L': ;
        break;
        case 'B': ;
        break;
        case 'P': ;
        break;
        case 'C': ;
        break;
        case 'E': ;
        break;
        default: printf("Select correct option...");
    }


return c_bal;
    }




int cash_withdrawls()
{


    return_point: ;
    char option;


    printf("How much money do you with to withdraw from your account..?\n");
        scanf("%d", &w_amount);
            fflush(stdin);




        if(w_amount > c_bal)
        {
                printf("Sorry you cannot withdraw %d, becuase you only have %d in your account...\n\n\n", w_amount ,c_bal);
                printf("Press Y to return to main or N to try again...");
                    scanf("%c", &option);


                    if( option == 'Y' || option == 'y')
                    {
                        main();


                    }
                    else if(option == 'N' || option == 'n')
                    {
                        goto return_point;
                    }




        }
        else if (w_amount < c_bal)
        {
                printf("Do sumn! ! ! !\n\n");
        }


    return c_bal;


}

Attached File  atn.jpg   260.67K   12 downloads
PePe===> BLACKSPADE EMPIRE<===PePe

www.blackspade-ent.com

#2
alex1

alex1

    Learning Programmer

  • Members
  • PipPipPip
  • 93 posts
Hi - I would suggest you to not use "goto" - it's called Spaghetti programming and will mess your programm up.
Try to use do while insted of it.

#3
Flying Dutchman

Flying Dutchman

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 889 posts
  • Location:::1
Using fflush on stdin is not defined - fflush is only defined for output streams. There are many sites/tutorials that show how to properly flush input stream.
A conclusion is where you got tired of thinking.
#define class struct    // All is public.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users