Thread: Part of ATM problem

  1. #1
    bignood
    Join Date
    Sep 2005
    Posts
    33

    Part of ATM problem

    Here is what I have so far

    Code:
    int get_data(int money)
    {
    int count2;
    int new_cash;
    int error;
    
     for    (count2 = 0; count2 < 100; count2 += 1){
            money = money % 10;
            if(money != 0){
            printf("This machine dispenses ONLY $50, $20, $10...\n\n");
            printf("Please enter again");
            scanf("%d", &money);
            new_cash = money;
            break;
    }       else
            new_cash = money * 10;
            
            }
    return(new_cash);
    
    
    }
    I have received money from main function. My ATM only gives out $10, $20, and $50 so it has to check if the user's cash request is correct.

    Right now, it either doesn't break out of the loop or it returns the wrong results. Thanks in advance.
    Last edited by 1rwhites; 10-26-2005 at 08:59 AM.

  2. #2
    Bioport Productions
    Join Date
    Oct 2005
    Posts
    215
    First of all, i'm suspicious about this line - money = money % 10...is that your check? That makes anything divisible by 10 true for your atm, you sayin I could get 200000 out of your atm? Ima switch to your bank, muhaha. A better solution would be to check each value, heres some psuedocode:

    WHILE
    money NOT EQUALS 50 OR 20 OR 10:
    print: money must be 50, 20 or 10, enter again
    money EQUALS NewMoneyEntered
    ENDWHILE

    return money
    -"What we wish, we readily believe, and what we ourselves think, we imagine others think also."
    PHP Code:
    sadf 

  3. #3
    Sys.os_type="Unix";;
    Join Date
    Aug 2005
    Posts
    52
    Most modern ATMs have a bill dispense limit, such as 15 bills per denomination ofcourse that's dependant upon which emulation the ATM is running such as Diebold, NCR and Fijitsu are some of the more popular ones.
    So if you have 10's and 20's which is generally the standard although some banks put in 5's or 50's then the max you could withdraw at one dispense with a 10 and 20 cassette would be 450.
    Don't know if this is actual production code for an ATM interface you're writing or just an assignment.
    Durban gave you some good psuedocode though for what you're asking for.

  4. #4
    Registered User
    Join Date
    Oct 2005
    Posts
    38
    I dont see what your trying to do with your function, please explain...

    tips: Use count2++ not count += 1, its nicer :P

    and as for the checking as durban said:
    if((m == 10) |(m == 20) ||(m == 50)) should work.

  5. #5
    bignood
    Join Date
    Sep 2005
    Posts
    33
    OK I Have this

    Code:
    int get_data(int money)
    {
    
    
    int count2;
    int new_cash;
    int error;
    
     for    (count2 = 0; count2 < 100; count2 += 1){
    int temp_money = money % 10;
           if(temp_money == 0){
            break;
            } else if((temp_money % 10) != 0)
            printf("\n\nThis machine dispenses ONLY $50, $20, $10...\n\n");
            printf("Please enter again");  
            scanf("%d", &money);
    }
    
    
    new_cash = money;
    return(new_cash);
    
    }
    Whenever I go through it the first time it doesn't work. But whenever it asks to enter the number again and I put in the same number it works. Does anybody see what I am doing wrong?

    As for everyones early suggestions, I am required to make it so that if it isn't able to make change with numbers divisble by 10 then it has to prompt the user to enter it again.

    thanks
    Last edited by 1rwhites; 10-27-2005 at 12:24 PM.

  6. #6
    Sys.os_type="Unix";;
    Join Date
    Aug 2005
    Posts
    52
    Quote Originally Posted by 1rwhites
    OK I Have this

    Code:
    int get_data(int money)
    {
    
    
    int count2;
    int new_cash;
    int error;
    
     for    (count2 = 0; count2 < 100; count2 += 1){
    int temp_money = money % 10;
           if(temp_money == 0){
            break;
            } else if((temp_money % 10) != 0)
            printf("\n\nThis machine dispenses ONLY $50, $20, $10...\n\n");
            printf("Please enter again");  
            scanf("%d", &money);
    }
    
    
    new_cash = money;
    return(new_cash);
    
    }
    Whenever I go through it the first time it doesn't work. But whenever it asks to enter the number again and I put in the same number it works. Does anybody see what I am doing wrong?

    As for everyones early suggestions, I am required to make it so that if it isn't able to make change with numbers divisble by 10 then it has to prompt the user to enter it again.

    thanks
    You're missing a parenthesis in your if statement block for one

    I just did this and it ran through correctly each time it asked me for a number i entered 15 25 35 and it kept asking.
    Code:
    #include <stdio.h>
    #include <string.h>
    
    int main()
    {
    
    int money = 15;
    int count2;
    int new_cash;
    int temp_money;
    
    	for    (count2 = 0; count2 < 100; count2++)
    	{
    		temp_money = money % 10;
    		if(temp_money == 0)
    		{
    			break;
    		} else if((temp_money % 10) != 0) 
    		{
    			printf("\n\nThis machine dispenses ONLY $50, $20, $10...\n\n");
            	printf("Please enter again : ");  
            	scanf("%d", &money);
    		}
    	}
    
    	new_cash = money;
    	printf("%d\n", new_cash);
    	return 0;
    }

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    The else if could be an else. And maybe you want to read in money instead of assigning it 15 each time?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  8. #8
    Sys.os_type="Unix";;
    Join Date
    Aug 2005
    Posts
    52
    Quote Originally Posted by dwks
    The else if could be an else. And maybe you want to read in money instead of assigning it 15 each time?
    That was a sample program I threw together in between coffee drinks.

  9. #9
    bignood
    Join Date
    Sep 2005
    Posts
    33
    OK here is my entire program. I still don't have this figured out. The first time I input for example 50, it says that the ATM can't make cash out of it. But when it prompts again I put in 50 and it works.
    I need for the ATM to accept any cash requests that are divisible by 10.

    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 main(void)
    {
    double open_bal;
    int cash;
    int new_cash;
    int money;
    
    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);
    
    printf("new cash %d", get_data(new_cash));
    
    return(0);
    }
    
    void bank_logo(void)
    {
    
    printf("$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
    printf("$                        $\n");
    printf("$  BankOne Money Access  $\n");
    printf("$                        $\n");
    printf("$       24 hours         $\n");
    printf("$    7 days a week       $\n");
    printf("$   All year long!!!     $\n");
    printf("$                        $\n");
    printf("$$$$$$$$$$$$$$$$$$$$$$$$$$\n\n\n");
    
    }
     
    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
            break;
    }
    if (count == 3)
            printf("\nYour chances are up.  Better luck next time.\n\n");
    }
    int get_data(int money)
    {
      while( TRUE )
      {
        /* test but dont change money */
        if(money % 10 == 0)
            { 
              return money;
        }else{
          printf("\n\nThis machine dispenses ONLY $50, $20, $10...\n\n");
          printf("Please enter again:> ");
          scanf("%d", &money);
        }
      }
    }

  10. #10
    Registered User
    Join Date
    Mar 2005
    Posts
    140
    You read into a variable named cash, but you pass new_cash to get_data


    you should change the way you check for 50, 20, or 10 or change your warning message to be consistent with what you actually allow (any multiple of 10)

    Edit: well you do have ... , so I guess that takes care of that :P
    Last edited by spydoor; 10-28-2005 at 11:41 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. file handling and function problem.
    By prepare in forum C Programming
    Replies: 7
    Last Post: 10-09-2004, 02:26 AM
  2. !!!Urgent Help on a group project!!!!!
    By AmeenR in forum C Programming
    Replies: 3
    Last Post: 12-13-2003, 09:22 PM
  3. Memory Problem - I think...
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 10-24-2001, 12:14 PM
  4. From stream/file to a string array problem
    By dradsws in forum C Programming
    Replies: 2
    Last Post: 10-01-2001, 06:24 PM