# programming

posted by .

Write a simple ATM program. Ask the user to enter their account number, and then print their beginning balance. (Just make one up). Then ask them if they want to make a deposit or a withdrawal. Depending on their selection, call a function to perform the action that they wish. Then print the new balance. They should be able to do as many transactions as they wish, so use iteration here.

• programming -

Would you like to share with us what you have done so far, and what problems you are encountering, if any?
It is also not clear which language should be used to write this program.

• programming -

Below is a small perl program which does the job. You may not know perl, but it should be possible to figure out what it's doing.

It does not validate input as a number, but it does illustrate some of the possible gotchas, and what can be done.

------------------------------------

print "Enter Account Number: ";
\$acct = <STDIN>;

\$bal = 500 + rand(500); #random balance from 500 to 1000
\$bal = int(\$bal*100)*.01; #restrict to 2 decimal places
printf "Current Balance: \\$%4.2f\n",\$bal;

while (1) {
print "Deposit(D) or Withdrawal(W) or Quit(Q) ? ";
until ((\$dw = <STDIN>) =~ /^\s*[dw]\s*\$/i) { # make sure onlt D or W is entered
exit if \$dw =~ /^q/i;
chomp \$dw;
print "\"\$dw\" is not a valid choice.\n";
print "Deposit(D) or Withdrawal(W)? ";
}
\$dw =~ s/\s+//g; # strip white space
\$dw = "\U\$dw"; # convert to upper case

if (\$dw eq "D") {
\$bal += update("Deposit");
} else {
\$bal -= update("Withdrawal",\$bal);
}

printf "New balance: \\$%4.2f\n",\$bal;
print "\nAnother transaction [Y]? ";
\$yn = <STDIN>;
last unless \$yn =~ /^y?\s*\$/i; #exit unless Y or <cr> entered
}

# Get deposit/withdrawal amount.
# This function does not validate input as number
sub update {
my (\$dw,\$cb) = @_; # get D/W and current balance
print "Amount of \$dw: \\$";
\$amt = <STDIN>;
return \$amt if \$dw eq "Deposit"; # allow any deposit
while (\$amt > \$cb) {
printf "You cannot withdraw \\$%4.2f -- balance is only \\$%4.2f
Please enter an amount less than \\$%4.2f: \\$",\$amt,\$cb,\$cb;
\$amt = <STDIN>;
}
return \$amt;
}

## Similar Questions

1. ### computer

Please read the following instructions (related project code) carefully: You'll be expected to observe good programming standards. • Project code must follow C++ syntax • Data used in each project must be retrieve and saved in …
2. ### C Programming

Write a program that prompts the user to enter a temperature, followed by a letter representing Celsius (C) or Fahrenheit (F). Then prompt the user for the conversion type and print the results to the screen with one decimal point. …
3. ### Computer Programming

/* Develop a C program that will determine if a department store customer has exceeded the credit limit on a charge account. For each customer, the following facts are available: a) account number b) Balance at the beginning of the …
4. ### programming and visual basic

These are two different types of questions, these are not the same questions The Some interest Credit Company provides loans to customers at 1.5 percent interest per month. Design an application that gets customer account data that …
5. ### computer science

You are required to use the Account class to simulate an ATM machine. Create ten accounts in an array with id 0, 1, 2 ...9, and initial balance \$50. The system prompts the user to enter an id. If the id is entered incorrectly, ask …
6. ### Programming in c++

Draw a flow-chart and Write a program that asks the user to enter students grades. The program should stop reading when the use enters ‘*’. In addition, your program should print the number of students got each grade. The grades …
7. ### Java programming

Write a Java program that stores Customer accounts with the attributes: (i) Name of the depositor (ii) Account number (iii) Type of account (iv) Balance amount And the methods: (i) Deposit (ii) Withdraw (iii) Display the balance You …
8. ### Java programming

can u give me some example of withdrawal money program using array to store ten information of user. including the attributes: (i) Name of the depositor (ii) Account number (iii) Type of account (iv) Balance amount And the methods: …
9. ### C programming

Build a program that allows a user to select one of the following four menu options: enter new integer value, print pointer address, print integer address, and print integer value. For this program you will need to create two variables: …
10. ### programming

Write a program which allows user to enter 10 student names and scores for Java programming 1 and Java programming 2. Allow user to choose which course they want to enter the record for. Use the loop to ask input from user. The program …

More Similar Questions