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.

  1. 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 800

    cout << 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;
    }

when i put in 'c 50' it prints but keeps printing the same thing continously not stopping unless i close it.

Your switch block:

//process what user inputs
switch (type)
{

is inside a while loop. Here's the start of the while loop:

while (type != 'E')

So this while loop will go round and round forever, until type is not E.

If type is C, will this loop ever end? No.

If i wanted the program to keep running until the user types E for the final balance how would i do that if the while statement didn't work? below is the new code. Also every time i put the amount into make it below 800 it runs fine but if i put an amount in that keeps it above 800 it does it twice. it is not reading the if statement.

void checking(float& amount, double& balance, char& type, double& totalservice)
{                               
    int numbbeloweight = 0;                         // initial number for below 800
    int numservice = 0;
    int numlesszero = 0;
    double servicetotal = totalservice;             
    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

//Determine which charges are needed


 if (balance >800)


cout << "Processing Check for $" << amount << endl;
    balance = balance - amount;
    numservice++;
    cout << "Balance: " << balance << endl;
    cout << "Service Charge:" << service << " for a check" << endl;
    servicetotal = (numservice * service) ;
    cout << "Total Service charges: $" << servicetotal << endl;


    else if (balance <800)

    cout << "Processing Check for $" << amount << endl;
    balance = balance - amount;
    numservice++;
    numbbeloweight =1;
    cout << "Balance: " << balance << endl;
    cout << "Service Charge:" << service << " for a check" << endl;
    servicetotal = (numservice * service) + beloweight ;
    cout << "Total Service charges: $" << servicetotal << endl;

    else if (balance <800 && balance <0)
    cout << "Processing Check for $" << amount << endl;
    balance = balance - amount;
    numservice++;
    numbbeloweight =1;
    cout << "Balance: " << balance << endl;
    cout << "Service Charge:" << service << " for a check" << endl;
    servicetotal = (numservice * service) + beloweight + negbalance;
    cout << "Total Service charges: $" << servicetotal << 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 800
balance = balance + amount;
cout << 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;

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;



switch (type)
{ 
 case 'D': deposit(amount, balance, type);
break;


case 'C': checking(amount, balance, type, totalservice);
break;


case 'E':
    cout << "Processing end of the month." << endl;
    totalservice = (numservice * service) + (numbbeloweight * beloweight) + (numlesszero*negbalance);
    cout << "Final Balance: " << balance - totalservice << endl;
break;

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;
}

If you dont use { and } around the contents of your if block, how long is the if block? It's until the next semi-colon.

So this:

if (balance >800)
cout << "Processing Check for $" << amount << endl;
    balance = balance - amount;
    numservice++;
    cout << "Balance: " << balance << endl;
    cout << "Service Charge:" << service << " for a check" << endl;
    servicetotal = (numservice * service) ;
    cout << "Total Service charges: $" << servicetotal << endl;

is the same as this:

if (balance >800)
{
  cout << "Processing Check for $" << amount << endl;
}
balance = balance - amount;
numservice++;
cout << "Balance: " << balance << endl;
cout << "Service Charge:" << service << " for a check" << endl;
servicetotal = (numservice * service) ;
cout << "Total Service charges: $" << servicetotal << endl;

Is that what you meant? See also the else if blocks.

Sorry stupid book's example didn't have the {}.
So i got it to read the first two if elseif, but the third one is still being ignored. I think i am missing something small because i have been staring at it for so long. and once again thank you gor your help

void checking(float& amount, double& balance, char& type, double& totalservice)
{                               
    int numbbeloweight = 0;         // initial number for below 800
    int numservice = 0;
    int numlesszero = 0;
    double servicetotal = totalservice;             
    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
    double newbalance = balance -amount;
//Determine which charges are needed


 if (newbalance > 800)

{

cout << "Processing Check for $" << amount << endl;
    newbalance = balance - amount;
    numservice++;
    cout << "Balance: " << newbalance << endl;
    cout << "Service Charge:" << service << " for a check" << endl;
    servicetotal = (numservice * service) ;
    cout << "Total Service charges: $" << servicetotal << endl;
}

    else if (newbalance < 800)
    {   
    cout << "Processing Check for $" << amount << endl;
    balance = balance - amount;
    numservice++;
    numbbeloweight =1;
    cout << "Balance: " << newbalance << endl;
    cout << "Service Charge:" << service << " for a check" << endl;
    servicetotal = (numservice * service) + beloweight ;
    cout << "Total Service charges: $" << servicetotal << endl;
}

    else if (newbalance < 0)
    {
    cout << "Processing Check for $" << amount << endl;
    balance = balance - amount;
    numservice++;
    numbbeloweight++; 
    cout << "Balance: " << newbalance << endl;
    cout << "Service Charge:" << service << " for a check" << endl;
    servicetotal = (numservice * service) + beloweight + (numbbeloweight * negbalance);
    cout << "Total Service charges: $" << servicetotal << endl;
}

Your code does this:

 if (newbalance > 800)
 {
   // do something
 }
 else if (newbalance < 800)
 {
  // do something else
 }
 else if (newbalance < 0)
 {
   // do a third different thing
 }

Tell me, what value of newbalance will make the third thing happen? When you have an answer, start at the top and go down and see which one of the three things happens.

Sorry got caught up in work.
Thank you for your help i saw where i was having the issue

I got it working all except the final end of month balance, i think i did the function wrong.
i thought making it third function would be easier to read.

void checking(float& amount, double& balance, char& type, double& totalservice)
{                               
    int numbbeloweight = 0;                         // initial number for below 800
    int numservice = 0;
    int numlesszero = 0;
    double servicetotal = totalservice;             
    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
    double newbalance = balance -amount;
//Determine which charges are needed


 if (newbalance > 800 )

{

cout << "Processing Check for $" << amount << endl;
    newbalance = balance - amount;
    numservice++;
    cout << "Balance: " << newbalance << endl;
    cout << "Service Charge:" << service << " for a check" << endl;
    servicetotal = (numservice * service) ;
    cout << "Total Service charges: $" << servicetotal << endl;
}

    else if (newbalance < 800 && newbalance >0)
    {   
    cout << "Processing Check for $" << amount << endl;
    balance = balance - amount;
    numservice++;
    numbbeloweight =1;
    cout << "Balance: " << newbalance << endl;
    cout << "Service Charge:" << service << " for a check" << endl;
    servicetotal = (numservice * service) + beloweight ;
    cout << "Total Service charges: $" << servicetotal << endl;
}

    else if (newbalance < 0)
    {
    cout << "Processing Check for $" << amount << endl;
    balance = balance - amount;
    numservice++;
    numlesszero = 1 ;
    cout << "Balance: " << newbalance << endl;
    cout << "Service Charge:" << service << " for a check" << endl;
    servicetotal = (numservice * service) + beloweight + (numlesszero* negbalance);
    cout << "Total Service charges: $" << servicetotal << 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 800
balance = balance + amount;
cout << 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;

cout << "Balance: " << balance << endl;
cout << "Total Service charges: $" << totalservice << endl;
}
void endofmonth( double& balance, char& type, double& totalservice)
        {

        int numservice;                                                                     // inital number of service charges
        int numlesszero;                                                                    // initial number for under zero
        int numbbeloweight; 
        double servicetotal = 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

        double endbalance = endbalance - servicetotal;                                      // balance entered
            cout << "Processing end of the month." << endl;
            totalservice = (numservice * service) + (numbbeloweight * beloweight) + (numlesszero*negbalance);
            cout << "Final Balance: " << balance - 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;

do{

    // 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;


switch (type)
{ 
 case 'D': deposit(amount, balance, type);
break;


case 'C': checking(amount, balance, type, totalservice);
break;
case 'E': endofmonth(balance, type, totalservice);
}

}while (type !='E');


    return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.