Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c++ and please add comments...thank you. 1) The attached file credits debits.cpp is a buggy version of a program to satisfy the requirements that follow.

c++ and please add comments...thank you.
image text in transcribed
image text in transcribed
1) The attached file credits debits.cpp is a buggy version of a program to satisfy the requirements that follow. Edit the file to satisfy the requirements. a) Start with a balance of $500 b) Each line of input should include an integer amount in SUS of a transaction, some white space, and then a description of the transaction. c) Stop the loop when the end of the input is detected. Note that since the line should start with the amount, we can take advantage of the implementation of >>, which returns if there is nothing left to match the desired type to read in d) If the amount is positive, it is a credit. If the amount is negative, it is a debit. Output description of transaction and indicate resulting balance c) If a dcbit would take the balance below zero a balance of exactly O is ok here), output crror message to the cerr stream instead of cout. Exit the loop but not the program (so you should still output the ending summary). 1) If the amount is zero, output error message to the cerr stream indicating that the transaction is invalid and will be ignored g) Output a summary of the transactions: Number of credit transactions Total amount of these credits Number of accepted debit transactions Total amount of these debits Final balance h) Here is a sample run: Reads in a list of bank transactions and outputs summary information Enter the amount of the next transaction in SUS), then the transaction description 30 returned desk lamp returned desk lamp of $30 leaves balance = $530 Enter the amount of the next transaction in SUS), then the transaction description -5 donuts donuts of $-5 leaves balance - $525 Enter the amount of the next transaction in SUS), then the transaction description O testing Ignoring transaction of 50 testing of so leaves balance - $525 Enter the amount of the next transaction in SUS), then the transaction description - 100 ATM withdrawal ATM withdrawal of $-100 leaves balance = $425 Enter the amount of the next transaction in SUS), then the transaction description -- 450 pay plumber to fix leak pay plumber to fix leak of $-450 is greater than balance - $425 Credits -1 Total credits - $30 Debits - 2 Total debits - $-105 Final balance - 425 /* CS 201 lab 3 Loops, part 1 */ #include #include #include #include using namespace std; int main() const int STARTING_BALANCE = 500; int balance = STARTING BALANCE; int amt; // of next transaction string desc; // description of transaction int numCredits, numDebits; int credit Sum, debitTotal; cout > amt; while (balance > 0) { numCredits = numDebits = creditSum = debitTotal = 0; if (amt > 0) { numCredits+1; creditSum + amt; else { numDebits+1; debitTotal = amt; balance - amt; getline (cin, desc); cout

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases In Action

Authors: Dave Bechberger, Josh Perryman

1st Edition

1617296376, 978-1617296376

More Books

Students also viewed these Databases questions