Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions 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
Check Mark
Knowledge Booster
Background pattern image
Computer Science
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
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education