#include #include #include #include // read/write to files #include // time(0) #include //setprecision() using namespace std; // prototypes void deposit(double* ptrBalance); void withdrawal(double* ptrBalance, float dailyLimit); // overloaded method - this version does not take withdrawal amount void withdrawal(double* ptrBalance, float dailyLimit, float amount); //overloaded method that takes withdrawal amount ///Entry point to the application int main() { // create constant values -- cannot be changed const int EXIT_VALUE = 5; const float DAILY_LIMIT = 400.0F; const string FILENAME = "Account.txt"; //create balance variable double balance = 0.0; // look for the starting balance; otherwise generate a ramdom starting balance ifstream iFile(FILENAME.c_str()); if (iFile.is_open()) { //did the file open? if so, read the balance iFile >> balance; iFile.close(); } else { // if the file did not open or doesnot exist, create a //random number for the starting balance srand(time(0)); const int MIN = 1000; const int MAX = 10000; balance = rand() % (MAX - MIN + 1) + MIN; } cout << fixed << setprecision(2) << "Starting Balance: $" << balance << endl; //let's create a pointer and set it to the balance variable location double* ptrBalance = &balance; // & means " address of" //pause before we clear the screen cout << "\nPress any key to continue .."; _getch(); //create loop variable BEFORE the loop short choice = 0; // start the application loop do { // show the menu system("cls"); // clears the console screen -- for Mac, use system ("clear"); cout << "Menu\n" << endl; cout << "1) Deposit" << endl; cout << "2) Withdrawal" << endl; cout << "3) Check Balance" << endl; cout << "4) Quick $40" << endl; cout << "5) Exit" << endl; // get user input cout << "\nEnter your choice: "; cin >> choice; //run code based on the user's choice switch (choice) { case 1: deposit(ptrBalance); //passing a pointer so only four bytes have to go across the system bus! break; case 2: withdrawal(ptrBalance, DAILY_LIMIT);// passing four byte pointer! cout << "Making a withdrawal..." << endl; break; case 3: // show the balance cout << fixed << setprecision(2) << "\nCurrent Balance: $" << endl; break; case 4: // get a quick $40 withdrawal(ptrBalance, DAILY_LIMIT, 40.0f); break; case 5: cout << "\nGoodbye" << endl; break; default: cout << "\nError. Please select from the menu." << endl; break; } // pause cout << "\nPress any key to continue..."; _getch(); } while (choice != EXIT_VALUE); // now that the application is over, write the new balance to the file ofstream oFile(FILENAME.c_str()); oFile << balance << endl; oFile.close(); return 0; // end of the main   ///Make a deposit void deposit(double* balance); { // get deposit and validate it float deposit = 0.0f; do { cout << "\nEnter deposit amount: "; cin >> deposit; if (cin.fail()) //did they give us a character instead of a number? { cin.clear(); //clears fail state cin.ignore(INT16_MAX, '\n'); // clears keyboard buffer cout << "\nError. Please use numbers only.\n" << endl; deposit = -1; //set deposit to a "bad" number continue; //restart the loop } if (deposit < 0.0f) // check for negative number cout << "\nError. Invalid deposit amount.\n" << endl; } while (deposit < 0.0f); // how do we get thedouble value located at the pointe? //Derefence it using an asterisk! balance += deposit; cout << fixed << setprecision(2) << "\nCurrent prt Balance: $" << balance << endl; // notice the asterisk } /// Make a withdrawal void withdrawal(double* ptrBalance, float dailyLimit); { // get the withdrawal float amount = 0.0f; cout << "\nEnter withdrawal amount: "; cin >> amount; // call the overloaded method version that takes // the balance, dailyLimit, and withdrawal amount withdrawal(ptrBalance, DAILY_LIMIT, amount); } /// Make a withdrawal - this overload accepts balance, dailyLimit, and withdrawal amount void withdrawal(double* ptrBalance, float dailylimit, float amount); { //take away money from the account and show the balance if (amount > DAILY_LIMIT) { cout << "\nError. Amount exceeds daily limit." << endl; } else if (amount > * ptrBalance) //notice the asterisk to derefence the pointer! { cout << "\nError. Insufficient funds." << endl; } else { *ptrBalance -= amount; //same as:*ptrBalance - amount; cout << "\nHere is your cash: $" << amount << endl; } cout << fixed << setprecision(2) << "\nCurrent Balance: $" << *ptrBalance << endl; }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Topic Video
Question

I am having error E0020 and E0140 in C++. How can I fix it?

/*Christopher Jimenez
CIS247C
ATM application
24 November */

// bring in our libraries
//Step #1
#include <iostream>
#include <conio.h>
#include <string>
#include <fstream> // read/write to files
#include <ctime> // time(0)
#include <iomanip> //setprecision()
using namespace std;

// prototypes
void deposit(double* ptrBalance);
void withdrawal(double* ptrBalance, float dailyLimit); // overloaded method - this version does not take withdrawal amount
void withdrawal(double* ptrBalance, float dailyLimit, float amount); //overloaded method that takes withdrawal amount

///Entry point to the application
int main()
{

// create constant values -- cannot be changed
const int EXIT_VALUE = 5;
const float DAILY_LIMIT = 400.0F;
const string FILENAME = "Account.txt";

//create balance variable
double balance = 0.0;

// look for the starting balance; otherwise generate a ramdom starting balance
ifstream iFile(FILENAME.c_str());

if (iFile.is_open())
{
//did the file open? if so, read the balance
iFile >> balance;
iFile.close();
}
else
{
// if the file did not open or doesnot exist, create a
//random number for the starting balance
srand(time(0));
const int MIN = 1000;
const int MAX = 10000;
balance = rand() % (MAX - MIN + 1) + MIN;

}

cout << fixed << setprecision(2) << "Starting Balance: $" << balance << endl;

//let's create a pointer and set it to the balance variable location
double* ptrBalance = &balance; // & means " address of"

//pause before we clear the screen
cout << "\nPress any key to continue ..";
_getch();


//create loop variable BEFORE the loop
short choice = 0;

// start the application loop
do {
// show the menu
system("cls"); // clears the console screen -- for Mac, use system ("clear");
cout << "Menu\n" << endl;
cout << "1) Deposit" << endl;
cout << "2) Withdrawal" << endl;
cout << "3) Check Balance" << endl;
cout << "4) Quick $40" << endl;
cout << "5) Exit" << endl;

// get user input
cout << "\nEnter your choice: ";
cin >> choice;

//run code based on the user's choice
switch (choice)
{
case 1:
deposit(ptrBalance); //passing a pointer so only four bytes have to go across the system bus!
break;
case 2:
withdrawal(ptrBalance, DAILY_LIMIT);// passing four byte pointer!
cout << "Making a withdrawal..." << endl;
break;

case 3:
// show the balance
cout << fixed << setprecision(2) << "\nCurrent Balance: $" << endl;
break;

case 4:
// get a quick $40
withdrawal(ptrBalance, DAILY_LIMIT, 40.0f);
break;

case 5:
cout << "\nGoodbye" << endl;
break;

default:
cout << "\nError. Please select from the menu." << endl;
break;
}

// pause
cout << "\nPress any key to continue...";
_getch();

} while (choice != EXIT_VALUE);

// now that the application is over, write the new balance to the file
ofstream oFile(FILENAME.c_str());
oFile << balance << endl;
oFile.close();

return 0;
// end of the main

 

///Make a deposit
void deposit(double* balance);
{
// get deposit and validate it
float deposit = 0.0f;
do
{
cout << "\nEnter deposit amount: ";
cin >> deposit;
if (cin.fail()) //did they give us a character instead of a number?
{
cin.clear(); //clears fail state
cin.ignore(INT16_MAX, '\n'); // clears keyboard buffer
cout << "\nError. Please use numbers only.\n" << endl;
deposit = -1; //set deposit to a "bad" number
continue; //restart the loop
}
if (deposit < 0.0f) // check for negative number
cout << "\nError. Invalid deposit amount.\n" << endl;
} while (deposit < 0.0f);
// how do we get thedouble value located at the pointe?
//Derefence it using an asterisk!
balance += deposit;

cout << fixed << setprecision(2) << "\nCurrent prt Balance: $" << balance << endl; // notice the asterisk
}

/// Make a withdrawal
void withdrawal(double* ptrBalance, float dailyLimit);
{
// get the withdrawal
float amount = 0.0f;
cout << "\nEnter withdrawal amount: ";
cin >> amount;

// call the overloaded method version that takes
// the balance, dailyLimit, and withdrawal amount
withdrawal(ptrBalance, DAILY_LIMIT, amount);
}
/// Make a withdrawal - this overload accepts balance, dailyLimit, and withdrawal amount
void withdrawal(double* ptrBalance, float dailylimit, float amount);
{
//take away money from the account and show the balance
if (amount > DAILY_LIMIT)
{
cout << "\nError. Amount exceeds daily limit." << endl;
}
else if (amount > * ptrBalance) //notice the asterisk to derefence the pointer!
{
cout << "\nError. Insufficient funds." << endl;
}
else
{
*ptrBalance -= amount; //same as:*ptrBalance - amount;
cout << "\nHere is your cash: $" << amount << endl;
}

cout << fixed << setprecision(2) << "\nCurrent Balance: $" << *ptrBalance << endl;
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 4 images

Blurred answer
Knowledge Booster
Instruction Format
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education