# Thread: Part of ATM problem

1. ## 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");
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.

2. 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

3. 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.

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. 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");
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

6. 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");
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");
scanf("%d", &money);
}
}

new_cash = money;
printf("%d\n", new_cash);
return 0;
}```

7. The else if could be an else. And maybe you want to read in money instead of assigning it 15 each time?

8. 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. 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");