Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: ATM simulation C program help please

  1. #1
    Join Date
    Oct 2004
    Posts
    3,198
    Rep Power
    0

    Exclamation ATM simulation C program help please

    Guys, i am creating an ATM bank simulation program. I'm just trying out case 1 first. It works and everything but i can't get it to loop back to the options menu to do another transaction. Instead, it doesn't respond when i select 'Y' or 'N' after being asked 'Another transaction?' . I know the code is not efficient so any assistance and advice would be appreciated a lot . See the code below, using Borland C++ v5.02. Getting it to loop back to options without closing is the main problem for me.


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

    int wit(int,int);

    int main()
    {
    int option,r,c;
    int pin;
    printf("The Bank ATM\n");
    printf("Please enter your Personal Identification Number");
    scanf("%d",&pin);
    if (pin==11)
    {
    printf("ACCESS GRANTED!");
    }
    else
    { return 0;
    system ("pause");
    }
    Loop:
    {clrscr();
    printf("enter an option from the menu below\n\n");
    printf("\t\t 1. Withdrawal \n");
    printf("\t\t 2. Deposit\n");
    printf("\t\t 3. Inquiry\n");
    printf("\t\t 4. Pay Bills/Credit Card\n");
    printf("Please enter your choice\n");
    scanf("%d", & option);
    switch (option)
    {
    case 1:
    printf("%d",wit(r,c));
    break;
    defaultrintf("please enter option\n");
    }
    return 0;
    } }
    int wit(int c, int r)
    {
    int newbal=0,current=100,request;
    char x;
    printf("Enter amount to withdraw: $\n");
    scanf("%d",&request);
    newbal=current-request;
    if(current>=request)
    {printf("Your balance after withdrawal is: $%d\n",newbal);
    system ("pause");
    printf("Another transaction? y or n?: ");
    scanf("%c",& x);
    if((x == 'y')||(x== 'Y'))
    {
    goto Loop;
    }
    else if((x =='n')||(x== 'N'))
    {
    printf("\nThank You for Banking with us");
    //getch();
    return 0;
    }
    }
    else
    {
    printf("Sorry, You do not have sufficient funds \n\n");
    system ("pause");
    //getch();

    }
    return 0;
    }

  2. #2
    Join Date
    Oct 2005
    Posts
    745
    Rep Power
    0

    Default

    Are while/do while loops out of the question...........,
    3.14159265358979323846264338327950288
    4197169399375105820974944592307816406
    28620899862803482534211706798 pi 101

  3. #3
    Join Date
    Oct 2004
    Posts
    3,198
    Rep Power
    0

    Default

    No they are not. They would actually be better but couldn't get it to work. Wouldn't mind replacing 'goto'.

  4. #4
    Join Date
    Feb 2005
    Posts
    3,450
    Rep Power
    0

    Default

    Aldayne, you sound like a first year UTECH student. I had an ATM simulation to do in my first year at UTECH as well. I'll send you my source code, when I can find it. PM, me your e-mail address.
    HTML Code:
    PM or link me                              Smartphone: Samsung Galaxy Note 8 SM-N950F
    CompTIA A+ Certified                       Laptop: Apple MacBook™ Pro
    ITIL v3  Certified                         Tablet: DELL Venue 11 Pro
                 Apple is still the best  thing since sliced bread

  5. #5
    Join Date
    Oct 2004
    Posts
    3,198
    Rep Power
    0

    Default

    Quote Originally Posted by NOKIA 3650
    Aldayne, you sound like a first year UTECH student. I had an ATM simulation to do in my first year at UTECH as well. I'll send you my source code, when I can find it. PM, me your e-mail address.
    Ok thanks. Is there advice or recommendations that you can give just viewing the code at post #1?

  6. #6
    Join Date
    Jan 2005
    Posts
    3,151
    Rep Power
    0

    Default

    lol nokia.. that is not the way to go. the man needs to do his work on his own.

  7. #7
    Join Date
    Feb 2005
    Posts
    3,450
    Rep Power
    0

    Default

    I didn't know that he seriously had this,as a project to do. I thought that this was something that he was doing in his spare time, out of sheer idleness.
    HTML Code:
    PM or link me                              Smartphone: Samsung Galaxy Note 8 SM-N950F
    CompTIA A+ Certified                       Laptop: Apple MacBook™ Pro
    ITIL v3  Certified                         Tablet: DELL Venue 11 Pro
                 Apple is still the best  thing since sliced bread

  8. #8
    Join Date
    Oct 2004
    Posts
    3,198
    Rep Power
    0

    Default

    Quote Originally Posted by NOKIA 3650
    I didn't know that he seriously had this,as a project to do. I thought that this was something that he was doing in his spare time, out of sheer idleness.
    Yeah, it's a little assignment, i've done one already without control structures. One with all statements in the cases. I am going to do it now with functions and control structures but kinda' hit a glitch here. Just seeking some advice and guidance from whoever willing to contribute.

  9. #9
    Join Date
    Feb 2006
    Posts
    1
    Rep Power
    0

    Default Try this

    Put the section between Loop: and goto Loop; in a do while loop. The if statement before goto Loop; is not necessary. Use it as the termination.
    do{
    :
    :
    :
    :
    }while((x == 'y')||(x== 'Y'));
    printf("\nThank You for Banking with us");
    //getch();
    return 0;

    not sure about the last else statement:

    else
    {
    printf("Sorry, You do not have sufficient funds \n\n");
    system ("pause");
    //getch();

    from your code it seems like the program would come here if the user doesn't press y, Y, n, N.

  10. #10
    Join Date
    Oct 2004
    Posts
    3,198
    Rep Power
    0

    Default

    Still working on it, thanks for suggestion Jesse but still getting 'undefined label 'Loop'' error. Gonna continue fooling around it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •