Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ ATM; recoding help. (Visual Studio) I have already posted this question on C

ID: 3751637 • Letter: C

Question

C++ ATM; recoding help. (Visual Studio)

I have already posted this question on Chegg, but it seems like the code is too complicated than it supposed to be. ( This is just a beginners class so I do not need any of these libraries except #include <iostream> and #include <string>

I would like the code to be simpler. ( Like cin.ignore(numeric_limits<streamsize>::max(),' ');)

I'll post the code at the very bottom.

Also, this is the prompt we are using.

#include <iostream>

#include<ios>

#include<limits>  

# include <string>

using namespace std;

//main function

int main() {

//variables to store users choices and amounts

char choice;

double with, depo, result, bal;

string accno;

//printing welcome message

cout << "+---------------------+" << endl;

cout << "| Joiner's Bank, Inc. |" << endl;

cout << "| CS215-003 |" << endl;

cout << "+---------------------+" << endl;

//getting the account number from user

cout << "Enter account number: ";

getline(cin, accno);

//checking whether account number equals to shutdown keyword

if (accno == "shutdown") {

cout << "shutting down...bye!" << endl;

return 0; //terminating the program

} else {

//if the account no is valid, then reading the balance from the user

cout << "Enter account balance: ";

cin >> bal;

cin.ignore(numeric_limits<streamsize>::max(),' ');

//displaying the menu options

cout << "B - Balance Enquiry" << endl;

cout << "D - Deposit" << endl;

cout << "W - Withdrawal" << endl;

cout << "Choose an option: " << endl;

cin >> choice;

//reapetadily asking the user for correct choice

do{

cout<<"""<<choice<<"""<<" is an invalid option. Enter B, D or W."<<endl;

cin >> choice;

}while(choice != 'D' && choice != 'B' && choice != 'W');

}

if (choice == 'B') {

//Displaying the account details

cout << "+---------------------+" << endl;

cout << "| Joiner's Bank, Inc. |" << endl;

cout << "+---------------------+" << endl;

cout << "Account: " << accno << endl;

cout << "Balance: $" << bal << endl;

}

if (choice == 'D') {

//getting the user deposit amount and storing into account

cout << "Enter deposit amount: ";

cin >> depo;

cout << "+---------------------+" << endl;

cout << "| Joiner's Bank, Inc. |" << endl;

cout << "+---------------------+" << endl;

cout << "Account: " << accno << endl;

cout << "Prev Bal: $" << bal << endl;

cout << "Deposit: $" << depo<<endl;

bal = bal + depo;

cout << "New Bal: $" << bal << endl;

}

if (choice == 'W') {

cout << "Enter withdrawl amount: ";

cin >> with;

while (with > bal) {

cout << "Insufficient funds. Current balance is $ "<<bal<<endl;

cout << "Enter withdrawl amount: ";

cin >> with;

}

bal = bal - with;

//displaying the account info

cout << "+---------------------+" << endl;

cout << "| Joiner's Bank, Inc. |" << endl;

cout << "+---------------------+" << endl;

cout << "Account: " << accno << endl;

cout << "Prev Bal: $" << bal << endl;

cout << "Withdrawn: $"<<with<<endl;

cout << "New Bal: $" << bal << endl;

}

return 0;

}

Project 1: ATM Learning Objectives: Use of the following to solve a problem C++basic data types, variables, assignments, arithmetic -user input/output - decisions basic loops General Description Write a C++ program that simulates the function of an ATM machine. For each transaction, the program asks the user to enter their current account number and balance (unrealistic, but we don't know how to read data from files yet) displays a menu of transaction options - - asks the user to choose an option, forcing them to enter a correct option - depending on the option chosen, asks for more information performs the calculations for the transaction prints the calculated amounts as a "receipt". The program repeats the above steps continuously until the user enters shutdown for the account number. This is a signal for the ATM to shut down (end program)

Explanation / Answer

The above code is simplified for your easy usage, since you have stated that you are beginner. The ignore command has not been used instead an if statement is added inorder to remove unwanted entries.

#include<iostream.h>

#include<string.h>

void main()

{

char choice;

double with, depo, result, bal; //declaring all the variables needed

string accno; //declaring account no as string

cout << "+---------------------+" << endl; //printing the welcome message

cout << "| Joiner's Bank, Inc. |" << endl;

cout << "| CS215-003 |" << endl;

cout << "+---------------------+" << endl;

//getting the account number from user

cout << "Enter account number: ";

cin>>accno; //getting account number using simple cin function because the account number doesnot have space inbetween, so to receive one string without space, cin function is enough.

//checking whether account number equals to shutdown keyword

if (accno == "shutdown") {

cout << "shutting down...bye!" << endl;

return 0; //terminating the program

} else {

//if the account no. is valid, then reading the balance from the user

cout << "Enter account balance: ";

cin >> bal;

if(bal>99999 || bal<0)

{ print("Enter your valid amount");

cin>>bal; }    //The ignore statement has been replaced with if.

//displaying the menu options

cout << "B - Balance Enquiry" << endl;

cout << "D - Deposit" << endl;

cout << "W - Withdrawal" << endl;

cout << "Choose an option: " << endl;

cin >> choice;

//reapetadily asking the user for correct choice

do{

cout<<"""<<choice<<"""<<" is an invalid option. Enter B, D or W."<<endl;

cin >> choice;

}while(choice != 'D' && choice != 'B' && choice != 'W');

}

if (choice == 'B') {

//Displaying the account details

cout << "+---------------------+" << endl;

cout << "| Joiner's Bank, Inc. |" << endl;

cout << "+---------------------+" << endl;

cout << "Account: " << accno << endl;

cout << "Balance: $" << bal << endl;

}

if (choice == 'D') {

//getting the user deposit amount and storing into account

cout << "Enter deposit amount: ";

cin >> depo;

cout << "+---------------------+" << endl;

cout << "| Joiner's Bank, Inc. |" << endl;

cout << "+---------------------+" << endl;

cout << "Account: " << accno << endl;

cout << "Prev Bal: $" << bal << endl;

cout << "Deposit: $" << depo<<endl;

bal = bal + depo;

cout << "New Bal: $" << bal << endl;

}

if (choice == 'W') {

cout << "Enter withdrawl amount: ";

cin >> with;

while (with > bal) {

cout << "Insufficient funds. Current balance is $ "<<bal<<endl;

cout << "Enter withdrawl amount: ";

cin >> with;

}

bal = bal - with;

//displaying the account info

cout << "+---------------------+" << endl;

cout << "| Joiner's Bank, Inc. |" << endl;

cout << "+---------------------+" << endl;

cout << "Account: " << accno << endl;

cout << "Prev Bal: $" << bal << endl;

cout << "Withdrawn: $"<<with<<endl;

cout << "New Bal: $" << bal << endl;

}

}

}