I have been working on this program for a couple of weeks now and am now behind in my online class. My professor is not answering any of my emails and I don't know what to do. I know the program is kind of a mess, but I am trying...I don't know why my void function won't read through after I compile I don't know what is missing. Thanks for any help
First, you're asking for a transaction type and amount to be entered at one time.
1 2
cout <<"Enter a Transcation Type and Transaction Amount: ";
cin >> command, check;
You ought to change your cin >> statement to look like this: cin >> command >> amount; You will have to creat the variable "amount"
next, right after you get that information, you're asking for more input in your if statements:
get ride of that cin >> command call your checks function with checks(amount, bbal, total);You have something similar after the deposit if statement:
1 2 3 4 5 6
if (command == 'd' || command == 'D')
{
cin >> deposit;
if (deposit > 0)
get rid of that cin >> deposit; part and instead use your amount variable which should have the value you need, assuming it was entered at your command line like it was a check... (just following your program's input instructions). That much will get you into your "void function" with more success for you to debug further.... ask if you have questions.
Thanks that helped so much. Another question. When I am trying to get the service charges to update they don't I get a service charge of .25 everytime. Why is it not updating?
I see where you tell the user they have a $.25 service charge for the check. But where in your program are you taking it out of the account balance? Remember you need to subtract "charge" from "nbal" at some point. What you've been doing is adding "charge" to your "nservicechage" variable so you can display the amount you wanted to charge, even though you never actually charge it from the balance.
I know I have to subtract it from the balance, but my assignment has me doing that later in the program. What I am having trouble with is adding the service charges. I changed service charge to
double servicecharge = 0.00 hoping that would work, but it doesn't either. I can't get my service charge to increment correctly. It is as if it is starting over each time the loop runs. How can I fix that and why is it happeing?
Please post your code again so I can see what's changed and try to run it.
Notice you have a parameter called servicecharges (with an 's' on the end) for your void function, but you declare one just called servicecharge and you never use the one with the 's' on the end... which is the one you have passed by reference so that it can go back to the function that called it.
#include <iostream> // input/output declarations
#include <iomanip> // i/o manupulator declarations
usingnamespace std;
void checks (double checkamount, double& balance, double& servicecharges);
void deposits (double depositamount, double& balance);
int main ()
{
char command; //transaction type
double amount; //check amount
double deposit; //deposit amount
double nbal=0; //new balance
double bbal; //begining balance
double ebal; //ending balance
constdouble charge = .25; //service charge
constdouble underbalcharge = 5.00;
constdouble nsf = 25.00;
double total=0;
double ntotal;
int count;
// Set up floating point output format
cout << setiosflags(ios::fixed | ios::showpoint) << setprecision(2);
// Type of program
cout <<"Checkbook Balancing Program\n";
// Get begining banance from the user
cout << "Enter the begining balance: \n";
cin >> bbal;
nbal = bbal; // ***
total = 0.00;
// Display User Commands
cout <<"Commands:\n";
cout <<"C - process a check\n";
cout <<"D - process a deposit\n";
cout <<"E - end the program\n";
do //start do loop
{
// Get transaction type from user
cout <<"Enter a Transaction Type: "; // ***
cin >> command;
if (command == 'c' || command == 'C')
{
cout << "Enter check amount: "; // ***
cin >> amount; // ***
checks (amount, nbal, total); // ***
}
elseif (command == 'd' || command == 'D')
{
cout <<"Enter deposit amount: "; // ***
cin >> deposit; // ***
if (deposit > 0)
{
cout <<"Processing deposit for $ " <<deposit<< endl;
nbal = nbal + deposit; // ***
cout <<"Balance is $ " <<nbal<< endl;
if (nbal < 800.00)
{
cout <<"Service charge : $5.00 Balance below $800.00\n";
total = total + underbalcharge; // ***
cout <<"Total service charges: $ "<<underbalcharge<< endl;
}
}
else
cout <<"Transaction must be a positive amount" << endl;
}
elseif (command == 'e' || command == 'E')
{
cout <<"Processing End of Month \n";
cout <<"Your balance at the end of the month was: " << nbal << endl;
ebal = nbal - total;
cout <<"You total service charges for the month is: " <<total<< endl; // ***
cout <<"Final Balance is $ " <<ebal<< endl;
system("pause"); // ***
return 0;
}
else
{
cout <<"Invalid command.\n";
cout <<"Please enter a Transaction command\n";
cout <<"C - process a check\n";
cout <<"D - process a deposit\n";
cout <<"E - end the program\n";
}
} while (bbal > 0);
system ("PAUSE");
return 0;
}
void checks (double checkamount, double& balance, double& servicecharges)
{
//check amount
double nbal; //new balance
//begining balance
double ebal; //ending balance
constdouble charge = .25; //service charge
constdouble underbalcharge = 5.00;
constdouble nsf = 25.00;
double ntotal;
int count;
double servicecharge = 0.00;
double nservicecharge;
if (checkamount > 0)
{
cout <<"Processing check for $ " <<checkamount<< endl;
nbal = balance-checkamount;
cout <<"Balance is $ " <<nbal<< endl;
cout <<"Service charge : $.25 for a check\n";
servicecharges = servicecharges + charge; // ***
if (nbal < 800.00)
{
cout <<"Service charge : $5.00 Balance below $800.00\n";
// nbal = nbal - underbalcharge;
servicecharges = servicecharges + underbalcharge; // ***
}
if (nbal < 0)
{
cout <<"Service charge : $25.00 Insufficient Funds\n";
// nbal = nbal - nsf;
servicecharges = servicecharges + nsf; // ***
cout <<"Total service charges: $ "<<servicecharges<< endl;
}
// else
// servicecharges = servicecharge + charge;
cout <<"Total service charges: $ "<<servicecharges<< endl;
}
else
cout <<"Transaction must be a positive amount" << endl;
balance = nbal; // ***
}
I have made a number of changes, and I tried to mark them with the comments // *** so you can review them.
I think I was able to understand how you wanted the program to work, so I didn't change the way it functions; at least I tried not to.
void deposits (double depositamount, double& balance)
} // this needs to be an opening brace {
double nbal;
double bbal;
if (deposit > 0)
{
cout <<"Processing deposit for $ " <<depositamount<< endl;
nbal = bbal+depositamount;
cout <<"Balance is $ " <<nbal<< endl;
}
else
cout <<"Transaction must be a positive amount" << endl;
} // add a closing brace it this is the end of your function
Could this boolean variable work? if I want the 5 lowbalance charge to only be charged once for the month if the balance goes under 800? this is what I have...