I need some assistance with a program I wrote and had to alter. Here are the initial instructions and what I initially had then my reworking and what I have now and any assistance would be helpful.
Write a C++ program to help you balance your checkbook at the end of the month. The program should have the user enter the initial balance followed by a series of transactions. For each transaction, first have the user enter a transaction type. The valid transaction types are:
C - process a check.
D - process a deposit.
E - do end of month processing and exit the program.
For checks and deposits, the user should be prompted to enter the transaction amount.
Service Charges
There is a $0.25 service charge for each check written. Keep a running total of the service charges.
Service charges are not deducted from the account balance until the end of the month.
Output
After each transaction, print
the command data (to confirm the transaction)
the resulting account balance
the total service charges accrued so far
Here is the code:
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
char choice = ' ';
double balance;
double amount;
double totalServiceCharge;
double serviceCharge = .25;
double numService = 0;
cout<<fixed<<showpoint<<setprecision(2);//displays 2 decimal points
cout<<"Checkbook Balancing program"<<endl;
cout<<"Please enter your beginning balance: ";//set balance
cin>>balance;
cout<<endl;
while (choice != 'e')
{
cout<<"Please enter a transaction code using lowercase letters."<<endl;
cout<<"C - Process a Check."<<endl;
cout<<"D - Process a Deposit."<<endl;
cout<<"E - Do end of month processing and exit program."<<endl;
cout<<"Transaction type: ";//setting up transaction type
cin>>choice;
if (choice == 'c' )
{
cout<<"Enter transaction amount: ";//loop for deposits
cin>>amount;//withdrawal amount
cout<<"Processing check for "<<amount<<endl;
balance = balance - amount;
cout<<"Balance: "<<balance<<endl;
cout<<"Service charge: $"<<serviceCharge<<" for a check"<<endl;
numService++;
totalServiceCharge = numService * serviceCharge;//sets up
//total trans amount and keeps track if any service charge
cout<<"Total service charges: $"<<totalServiceCharge<<endl;
}//if 'c'
else if (choice == 'd')
{
cout<<"Enter transaction amount: ";//loop takes care of deposits
cin>>amount;//amount for deposit
cout<<"Processing deposit for "<<amount<<endl;
balance = balance + amount;
cout<<"Balance: "<<balance<<endl;
totalServiceCharge = numService * serviceCharge;
cout<<"Total service charges: $"<<totalServiceCharge<<endl;
}//else if 'd'
else if (choice == 'e')
{
cout<<"Processing end of the month "<<endl;//loop tallies up fees, withdrawals and deposits
totalServiceCharge = numService * serviceCharge;
cout <<"Final Balance: "<<balance - totalServiceCharge<<endl;
}//else if 'e'
else
{
cout<<"Please enter a valid transaction type"<<endl;//as long as E is not selected
}//else
}//while choice!='e'
return 0;
}//main
Modify your checkbook balancing program from assignment 2 as follows:
The user should enter the transaction type and amount (if required) on a single line. In other words, there should not be a separate prompt message for the transaction amount.
Use a separate function to do check processing and another function to do deposit processing.
Add additional service charges (see below).
The program commands are as follows (see the sample program dialog near the bottom of this page).
Transaction command Meaning
C amount Process a check for amount dollars, where amount is a floating-point number.
D amount Process a deposit for amount dollars, where amount is a floating-point number.
E End the program.
Service Charges
There is a $0.25 service charge for each check written.
If the account balance falls below $800.00 at any time during the month, there is a $5.00 service charge for the month. NOTE: This fee is only charged once at most!
If processing a check results in a negative balance, there is a $25 service charge (insufficient funds charge). This $25 fee is charged for each check that results in a negative balance.
Note: all service charges should be deducted from the account balance at the end of the month.
Output
For each transaction, print
the command data (to confirm the transaction)
the resulting account balance
the total service charges accrued so far.
I have reworked this code and now I have this and not sure what I did wrong:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
char choice = ' ';//user choice of transaction type
double balance = 0.0;//initial balance of the account
double totalServCharge = 0.0;
//set all amounts entered to have two decimal places displayed
cout<<fixed<<showpoint<<setprecision(2);
cout << "Checkbook Balancing program - Ver. 2.0" <<endl;
cout << "Please enter your beginning blance: ";
cin >> balance;
cout << endl;
//main menu
cout << "Please enter a transaction code using uppercase letters. "<<endl;
cout << "C - Process a Check"<<endl;
cout << "D - Process a Deposit"<<endl;
cout << "E - Do end of month processing and exit program"<<endl;
//how the program chooses what transaction to use
while (choice != 'E')
{
cout << "Transaction type: ";
cin >>choice;
//choice "c"
if (choice == 'c')
{
choiceC(double balance);
}
//choice 'd'
else if (choice == 'd')
{
choiceD(double balance, double totalServCharge);
}
else if (choice == 'e')
{
choiceE(double balance, double totalServCharge);
}
else
{
cout << "please enter a valid transaction type" << endl;
}
}
return 0;
}
double choiceC(double balance, double totalServCharge)
{
int numServCharge = 0;
int numLessEight = 0;
int numLessZero = 0;
const double SERVICE = .25;
const double LESSEIGHT = 5.0;
const double LESSZERO = 25.0;
double amount = 0.0;
cout << "please enter your tansaction amount: ";
cin >> amount;
//error statement if amount is negative
if (amount < 0)
{
cout << "a negative is a non-valid entry please try your transaction again"<<endl;
cout << "Please enter your transaction amount :";
cin >> amount;
}
//corect input by user
else if (amount > 0)
{
cout<<"Processing check for: $"<<amount<<endl;
}
//calculations for check balance
balance = balance - amount;
//balance condition statements
if (balance < 800)
{
cout << balance <<endl;
cout <<"Balance: "<<balance<<endl;
cout << "Service charge: $" << SERVICE << " for a check"<<endl;
cout << "serivce charge: $" << LESSEIGHT << " for a balance less than $800"<<endl;
numServCharge++;
numLessEight = 1;
}
else if (balance < 0)
{
cout <<"Balance: "<<balance<<endl;
cout << balance <<endl;
cout << "Service charge: $" << SERVICE << " for a check"<<endl;
cout << "Service charge: $" << LESSZERO << " for a balance less than $0.0" << endl;
numServCharge++;
numLessZero++;
totalServCharge = (numServCharge * SERVICE) + (numLessEight * LESSEIGHT) + (numLessZero * LESSZERO);
cout << totalServCharge <<endl;
return balance, totalServCharge;
}
}
double choiceD(double balance, double totalServCharge)
{
double amount = 0.0;
cout <<"Enter transaction amount: ";
cin >>amount;
//error statment for negative amount
if (amount < 0)
{
cout << "a negative is a non-valid entry please try your transaction again"<<endl;
cout << "Please enter your transaction amount :";
cin >> amount;
}
else if (amount > 0)
{
cout<<"Processing check for: $"<<amount<<endl;
}
cout<<"Processing deposit for: $"<<amount<<endl;
//calculate deposit amount
balance = balance + amount;
cout <<"Balance: "<<balance<<endl;
//calculate the total amount of service charges
cout <<"Total service charges: $"<<totalServCharge<<endl;
return balance, totalServCharge;
}
double choiceE(double balance, double totalServCharge)
{
cout <<"Processing end of the month "<<endl;
cout <<"Your total service charges were: $" <<totalServCharge <<endl;
cout <<"Final Balance: "<<balance - totalServCharge<<endl;
//if final balance is negative
if (balance < 0)
{
cout << "You owe us money!";
}
return 0;
}
Please can I get some guidance.