C++, create an atm program. The starting balance at $5000. Enter a user-input lo
ID: 660945 • Letter: C
Question
C++, create an atm program. The starting balance at $5000. Enter a user-input loop giving the user 4 choices (W,D,B, Q) . User is allowed to enter a single character or an entire word. The program continues until and unless the user has entered a 'q', 'Q', or ''Quit', etc., in which case the program should end. When the user is asked to enter a number, you can assume he does not type some non-numeric value. You don't have to test for this kind of error. Use logical operators to simplify if statements, and getline() is used everywhere - do not mix cin with getline()...
===== ===== ===== ===== Question ===== ===== ===== ===== ===== =====
I cannot get the program to accept the user entering a lowercase letter or word from the menu options. The program errors and closes. Something is wrong with the string being carried over from getline() into an IF statement. Also, I need the program to loop if the user errors. It can only end if they choose to Quit, Q, or q. I know I should have a do/while statement, but where should that begin and end ?
===== ===== ===== ===== ===== ===== ===== ===== ===== ===== =====
#include <iostream>
#include <string>
using namespace std;
int main()
{
float Balance = 5000.00; // account balance
string acct_option;
float amount;
//Menu for selection
cout << "Please select an option (W, D, B, or Q): " << endl;
cout << "W (Withdrawal)" << endl;
cout << "D (Diposit) " << endl;
cout << "B (Show Balance) " << endl;
cout << "Q (Quit)" << endl;
getline(cin, acct_option);
cout << acct_option;
if (acct_option == 'W' || acct_option == 'w') // if option W selected
{
cout << "Please enter amount to withdraw : " << endl << endl;
cin >> amount; // enter amount to withdraw
if (amount <= 0)
{
cout << "Amount cannot be zero or negative" << endl;
}
else if (amount > Balance) // if withdrawn
{
cout << "You do not have enough funds to withdraw this amount" << endl;
}
else // withdraw funds
{
Balance = Balance - amount;
cout << "Withdrawl has been processed. Your new balance is " << Balance << endl;
}
}
else if (acct_option == 'B') // if user enters option B
{
cout << "Your Balance is " << Balance << endl;
}
if (acct_option == 'D' || 'd') // if user enters option D
{
cout << "Please enter deposit amount: " << endl;
Balance = Balance + amount;
cin >> amount; // enter amount to deposit
cout << " Deposit has been processed. Your new balance is: " << Balance << endl;
}
if (acct_option == 'Q' || 'q') // if user enters option Q
{
cout << "No transaction processed" << endl << endl;
}
else
{
cout << "Invalid Option Selected." << endl << endl;
}
cout << "Thank You, Enjoy Your Day!" << endl;
return 0;
}
Explanation / Answer
I have coded another one. Please go through it.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.