Thread: ATM trouble???

  1. #1
    bignood
    Join Date
    Sep 2005
    Posts
    33

    ATM trouble???

    OK here is a piece of my program:

    Code:
    #include<stdio.h>
    #include<math.h>
    #define PIN 2424
    #define TRUE 1
    
    /* Function Prototypes */
    void bank_logo(void);
    
    void validate_pin(void);
    
    int get_data(int money);
    
    int get_balance(double balance, int bal_cash);
    
    void fifties_twenties_tens(int tot_bal, int *fifty, int *twenty, int *ten);
    
    int main(void)
    {
    double open_bal;
    int cash;
    int new_cash;
    int money;
    int balance_cash;
    int fif;
    int twen;
    int tens;
    int remaining_balance;
    
    bank_logo();
    validate_pin();
    
    printf("Enter the opening balance of your account  $");
    scanf("%lf", &open_bal);
     printf("Enter how much cash you need?  $");
    scanf("%d", &cash);
    
     balance_cash = get_data(cash);
    printf("\nThe amount you are withdrawing =  %d\n", balance_cash);
    
    remaining_balance = get_balance(open_bal, balance_cash);
    printf("Remaining Balance in your account = %d\n\n", remaining_balance);   
    printf("    *** Take your cash as $$$ bills ***    \n\n");
    
    fifties_twenties_tens(balance_cash, &fif, &twen, &tens);
    
    printf(" %5d fifty %5d twenties and %5d tens\n\n", fif, twen, tens);
    /*
    printf(" %5d fifty %5d twenties and %5d tens", fifties_twenties_tens(balance_cash, &fif, &twen, &tens);
    */
    return(0);
    }
    
    
    void validate_pin(void)
    {
    int id; /* input of user's PIN number */
    int count;
    
    for (count = 0; count < 3; ++count){
    
    printf("Enter your 4-digit personal identification (PIN) >>  ");
    scanf("%d", &id);
            if (id != PIN)
            printf("Sorry! Invalid PIN number !\n");
            else if (count == 3)
            printf("\nYour chances are up.  Better luck next time.\n\n");
            else
            break;
           }
    
    }
    What I want it to do in function validate_pin is if the user fails to enter the the PIN number after 3 tries, I want it to print Your chances are up. Better luck next time. And then end the program. But if the enter the PIN within 3 tries to continue with the program.

  2. #2
    Bioport Productions
    Join Date
    Oct 2005
    Posts
    215
    wrap it in a while statement, while(pin != correctpin && trys < 3)
    -"What we wish, we readily believe, and what we ourselves think, we imagine others think also."
    PHP Code:
    sadf 

  3. #3
    bignood
    Join Date
    Sep 2005
    Posts
    33
    I'm sorry I'm confused. What am I wrapping in a while statement??

  4. #4
    Bioport Productions
    Join Date
    Oct 2005
    Posts
    215
    Instead of using the for loop, use a while loop:

    Code:
    for (count = 0; count < 3; ++count){
    
    printf("Enter your 4-digit personal identification (PIN) >>  ");
    scanf("%d", &id);
            if (id != PIN)
            printf("Sorry! Invalid PIN number !\n");
            else if (count == 3)
            printf("\nYour chances are up.  Better luck next time.\n\n");
            else
            break;
           }
    -"What we wish, we readily believe, and what we ourselves think, we imagine others think also."
    PHP Code:
    sadf 

  5. #5
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    How about:
    Code:
    for(count = 0;count < 3;++count)
    {
      ask for PIN
      if the entered PIN matches then break out of the loop with break statement
    }
    if count equals 3
      print they're out of turns and exit
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trouble with assignment in C
    By mohanlon in forum C Programming
    Replies: 17
    Last Post: 06-23-2009, 10:44 AM
  2. Replies: 6
    Last Post: 01-03-2007, 03:02 PM
  3. Is it so trouble?
    By Yumin in forum Tech Board
    Replies: 4
    Last Post: 01-30-2006, 04:10 PM
  4. trouble scanning in... and link listing
    By panfilero in forum C Programming
    Replies: 14
    Last Post: 11-21-2005, 12:58 PM
  5. C++ program trouble
    By senrab in forum C++ Programming
    Replies: 7
    Last Post: 04-29-2003, 11:55 PM