I have been hitting a brick wall with this program. I am new at c++ and the text only shows really really easy examples. the deposit function works fine, but i am running into problems with the checking function and doing the final output.
1. when i type in 'C 50' it is supposed to take it out of the balance show service amount and if below 800 add that charge to total service. when i put in 'c 50' it prints but keeps printing the same thing continously not stopping unless i close it. the program suing switch statements compiles fine so i am not sure why it does this.
When i type 'E' to show the end of month processing nothing happens. not sure why. i know it has something to do with the way i've typed it but i am not sure how to fixe it.
I have tried if/else if statements and switch statements for the entire program. in visual basic the program ran but didn't show the added charges for below 800 or a negative balance. now I am using devc++ that version (if/else if way) gives me new errors.
Any help would be appreciated. I don't feel comfortable moving to my next project until i can figure this one out if that makes sense.//Check Book Balancing program
// Programmer: Erica Drew
// Completed : 3/7/2015
// Status : Complete
//
// This checkbook balancing program takes user input and balances it.
//Giving the user the monthly ending balance minus fee at when they end the program.
//It adds in a fee for balance under $800 and a fee for negative balances.include <iostream>include <iomanip>using namespace std;
void checking(float& amount, double& balance, char& type, double& totalservice )
{
int numbbeloweight = 0; // initial number for below 800
int numservice = 0;
int numlesszero = 0;const double service = .25; // service amount const double beloweight = 5.00; // Fee for going under $800 const double negbalance = 25.00; //Fee for negative balance cout << fixed << showpoint << setprecision(2); //displays 2 decimal points cout << "Entered transaction type: " << type << endl; cout << "Entered transaction amount:" << amount << endl; cout << "Processing Check for $" << amount << endl; balance = balance - amount; cout << "Balance: " << balance << endl; cout << "Service Charge:" << service << " for a check" << endl; numservice++; totalservice = numservice * service; cout << "Total Service charges: $" << totalservice << endl;
}
void deposit(float& amount, double& balance, char& type)
{
double totalservice; // total service charge
int numservice = 0; // inital number of service charges
int numlesszero = 0; // initial number for under zero
int numbeloweight = 0; // initial number for below 800cout << fixed << showpoint << setprecision(2); //displays 2 decimal points cout << "Entered transaction type: " << type << endl; cout << "Entered transaction amount: " << amount << endl; cout << "Processing Deposit for $" << amount << endl; balance = balance + amount; cout << "Balance: " << balance << endl; cout << "Total Service charges: $" << totalservice << endl;
};
int main()
{
//variables function
char type ; // types of transactions
float amount; // amount entered
double balance; // balance entered
int numservice; // inital number of service charges
int numlesszero; // initial number for under zero
int numbbeloweight;
double totalservice; // total service charges at end of program
const double service = .25; // service amount
const double beloweight = 5.00; // Fee for going under $800
const double negbalance = 25.00; //Fee for negative balance//start program cout << "Balancing Your Checkbook Program" << endl; cout << "Enter Your balance: \n"; // Starts your balance cin >> balance; // Main menu cout << "Please enter type of transaction type and amount \n"; cout << "C - checks" << endl; cout << "D - deposits " << endl; cout << "E - exit and show end balance." << endl; cin >> type >> amount;
//make sure user puts in positve number
while (amount <=0)
{ //error statement for negative amount
cout << "Please enter a positive number (larger than zero): ";
cin >>amount;
}
while (type != 'E')//process what user inputs
switch (type)
{case 'd':
case 'D': deposit(amount, balance, type);
break;case'c':
case 'C': checking(amount, balance, type, totalservice);
break;case 'e':
case 'E':
cout << "Processing end of the month." << endl;
totalservice = (numservice * service) + (numbbeloweight * beloweight) + (numlesszero*negbalance);
cout << "Final Balance: " << balance - totalservice << endl;default:
cout << "Please enter type of transaction type and amount \n";
cout << "C - checks" << endl;
cout << "D - deposits " << endl;
cout << "E - exit and show end balance." << endl;
cin >> type >> amount;}
return 0;
}