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;
}
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 4 images
- FileAttributes.c 1. Create a new C source code file named FileAttributes.c preprocessor 2. Include the following C libraries a. stdio.h b. stdlib.h c. time.h d. string.h e. dirent.h f. sys/stat.h 3. Function prototype for function printAttributes() main() 4. Write the main function to do the following a. Return type int b. Empty parameter list c. Declare a variable of data type struct stat to store the attribute structure (i.e. statBuff) d. Declare a variable of data type int to store an error code (i.e. err) e. Declare a variable of data type struct dirent as a pointer (i.e. de) f. Declare a variable of data type DIR as a pointer set equal to function call opendir() passing explicit text “.” as an argument to indicate the current directory (i.e. dr) g. If the DIR variable is equal to NULL do the following i. Output to the…arrow_forwardException in thread "main" java.lang.NumberFormatException: For input string: "x" for Java code public class Finder { //Write two recursive functions, both of which will parse any length string that consists of digits and numbers. Both functions //should be in the same class and have the following signatures. //use the if/else statement , Find the base case and -1 till you get to base case //recursive function that adds up the digits in the String publicstaticint sumIt(String s) { //if String length is less or equal to 1 retrun 1. if (s.length()<= 1){ return Integer.parseInt(s); }else{ //use Integer.praseInt(s) to convert string to Integer //returns the interger values //else if the CharAt(value in index at 0 = 1) is not equal to the last vaule in the string else {//return the numeric values of a char value + call the SumIt method with a substring = 1 return Character.getNumericValue(s.charAt(0) ) + sumIt(s.substring(1)); } } //write a recursion function that will find…arrow_forward// Program describes two files // tells you which one is newer and which one is larger import java.nio.file.*; import java.nio.file.attribute.*; import java.io.IOException; public class DebugThirteen1 { public static void main(String[] args) { Path file1 = Paths.get("/root/sandbox/DebugDataOne1"); Path file2 = Paths.get("/root/sandbox/DebugDataOne2.txt"); try { BasicFileAttributes attr1 = Files.readAttributes(file1, BasicFileAttributes.class); System.out.println("File: " + file1getFileName()); System.out.println("Creation time " + attr1.creationTime()); System.out.println("Last modified time " + attr1lastModifiedTime()); System.out.println("Size " + attr1.size()); BasicFileAttributes attr2 = Files.readAttributes(file2, BasicFileAttributes.class); System.out.println("\nFile: " + file2.getFileName); System.out.println("Creation time " +…arrow_forward
- In python, rite a recursive function, displayFiles, that expects a pathname as an argument. The path name can be either the name of a file or the name of a directory. If the pathname refers to a file, its filepath is displayed, followed by its contents, like so: File name: file_path Lorem ipsum dolor sit amet, consectetur adipiscing elit... Otherwise, if the pathname refers to a directory, the function is applied to each name in the directory, like so: Directory name: directory_path File name: file_path1 Lorem ipsum dolor sit amet... File name: file_path2 Lorem ipsum dolor sit amet... ... Test this function in a new program.arrow_forwardDebug // Program describes two files // tells you which one is newer and which one is larger import java.nio.file.*; import java.nio.file.attribute.*; import java.io.IOException; public class DebugThirteen1 { publicstaticvoidmain(String[] args) { Path file1 = Paths.get("/root/sandbox/DebugDataOne1"); Path file2 = Paths.get("/root/sandbox/DebugDataOne2.txt"); try { BasicFileAttributes attr1 = Files.readAttributes(file1, BasicFileAttributes.class); System.out.println("File: " + file1getFileName()); System.out.println("Creation time " + attr1.creationTime()); System.out.println("Last modified time " + attr1lastModifiedTime()); System.out.println("Size " + attr1.size()); BasicFileAttributes attr2 = Files.readAttributes(file2, BasicFileAttributes.class); System.out.println("\nFile: " + file2.getFileName); System.out.println("Creation time " + attr2.creationTime()); System.out.println("Last modified time " + attr2.lastModifiedTime()); System.out.println("Size " + attr2.size());…arrow_forwardImplement in C Programming 9.6.1: LAB: File name change A photographer is organizing a photo collection about the national parks in the US and would like to annotate the information about each of the photos into a separate set of files. Write a program that reads the name of a text file containing a list of photo file names. The program then reads the photo file names from the text file, replaces the "_photo.jpg" portion of the file names with "_info.txt", and outputs the modified file names. Assume the unchanged portion of the photo file names contains only letters and numbers, and the text file stores one photo file name per line. If the text file is empty, the program produces no output. Assume also the maximum number of characters of all file names is 100. Ex: If the input of the program is: ParkPhotos.txt and the contents of ParkPhotos.txt are: Acadia2003_photo.jpg AmericanSamoa1989_photo.jpg BlackCanyonoftheGunnison1983_photo.jpg CarlsbadCaverns2010_photo.jpg…arrow_forward
- Language: Java Rewrite the ADA source code in Java.Within the Java version of the code, change the second half of the first loop so that all assignments to the counting array 'Freq()' are updated in the EXCEPTION portion of the code. There should be no valid updates to 'Freq()' anywhere else in the loop.ADA source code:with Ada.Text_IO , Ada.Integer_Text_IO ;use Ada.Text_IO, Ada.Integer_Text_IO;procedure Grade_Distribution isFreq: array (1..10) of Integer := (others => 0);New_Grade : Natural;Index,Limit_1,Limit_2 : Integer;beginGrade_Loop:loopbeginGet(New_Grade);exceptionwhen Constraint_Error =>exit Grade_Loop;end;Index := New_Grade/10 + 1;beginFreq(Index) := Freq(Index) +1 ;exceptionwhen Constraint_Error =>if New_Grade = 100 thenFreq(10) := Freq(10) + 1;elsePut("Error -- new grade: ");Put(New_Grade);Put(" is out of range");New_Line;end if;end;end loop Grade_Loop;Put("Limits Frequency");New_Line; New_Line;for Index in 0..8 loopLimit_1 := 10 * Index;Limit_2 := Limit_1 + 9;if…arrow_forwardsource code: import java.util.*;import java.io.*; public class Main { static File text = new File("/Users/.../Desktop/sourceCode.txt"); static FileInputStream keyboard; static int charClass; static char lexeme[] = new char[100]; //stores char of lexemes static char nextChar; static int lexLen;// length of lexeme static int token; static int nextToken; // Token numbers static final int LETTER = 0; static final int DIGIT = 1; static final int UNKNOWN = 99; static final int INT_LIT = 10; static final int IDENT = 11; static final int ASSIGN_OP = 20; static final int ADD_OP = 21; static final int SUB_OP = 22; static final int MULT_OP = 23; static final int DIV_OP = 24; static final int LEFT_PAREN = 25; static final int RIGHT_PAREN = 26; public static void main(String[] args) { try{ keyboard = new FileInputStream(text); getChar(); do { lex(); }while…arrow_forwardWrite a C++ program where one function throws an exception, and another function catches and handles itarrow_forward
- Please help me fix my errors in Python. def read_data(filename): try: with open(filename, "r") as file: return file.read() except Exception as exception: print(exception) return None def extract_data(tags, strings): data = [] start_tag = f"<{tags}>" end_tag = f"</{tags}>" while start_tag in strings: try: start_index = strings.find(start_tag) + len(start_tag) end_index = strings.find(end_tag) value = strings[start_index:end_index] if value: data.append(value) strings = strings[end_index + len(end_tag):] except Exception as exception: print(exception) return data def get_names(string): names = extract_data("name", string) return names def get_descriptions(string): descriptions = extract_data("description", string) return descriptions def get_calories(string): calories = extract_data("calories", string) return…arrow_forwardData structure: Using Java,arrow_forwardJava Problem The teacher at a school needs help grading an exam with a number of True/False questions. The students’ IDs and test answers are stored in a file. The first entry of the file contains the answer to the test in the form: TTFTFTTTFTFTFFTTFTTF Every other entry in the file is the student’s ID, followed by a blank, followed by the students’ response. For instance, the entry: ABC54102 T FTFTFTTTFTTFTTF TF The student’s ID is ABC54102, answer to question 1 is True, the answer to question 3 is False. Also, the student did not answer question 2 and question 18. The exam has 20 questions. Here is the grading policy: each correct answer is awarded two points, each wrong answer get -1 point, and no answer gets 0 point. Write a program that processes the test data. The output should be the student’s ID, followed by the answers, followed by the test score (total points), followed by the test grade. Assume the following grade scale will be used: 90%-100%, A; 80%-89.99%, B; 70%-79.99%,…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education