My credit limit program doesn't produce the desired output

This is a discussion on My credit limit program doesn't produce the desired output within the C++ Programming forums, part of the General Programming Boards category; Hello, I have a new program which I am working on and I need some guidance with it. This program ...

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    71

    My credit limit program doesn't produce the desired output

    Hello,

    I have a new program which I am working on and I need some guidance with it. This program has to determine whether a department-store customer has exceeded the credit limit on a charge account.
    I am instructed to use a while loop to input each of the facts, calculate the new balance using this equation - balance = beginning balance + charges - credit, and determine wheter the new balance exceeds the customer's credit limit.
    This is what the output should look like -

    Enter account number ( -1 to end ): 100
    Enter the beginning balance: 5394.78
    Enter total charges: 1000.00
    Enter total credits: 500.00
    Enter credit limit: 5500.00
    Account: 100
    Credit Limit: 5500.00
    Balance: 5894.78
    Credit Limit Exceeded

    Enter account number ( -1 to end ): 200
    Enter the beginning balance: 1000.00
    Enter total charges: 123.45
    Enter total credits: 100.00
    Enter credit limit: 1500.00

    Enter account number ( -1 to end): -1

    This is what my code lookslike so far -
    Code:
    #include<iostream>
    #include<conio>
    #include<iomanip>
    using namespace std;
    
    int main(int argc, char* argv[])
    {
       int      accountNumber;
       double   beginningBalance;
       double   totalCharges;
       double   totalCredits;
       double   creditLimit;
       double   balance;
    
       balance = beginningBalance + totalCharges - totalCredits;
    
       cout << setprecision( 6 ) << fixed;
    
       while( accountNumber != -1 ) {
          cout << "Enter account Number: " << endl;
          cin >> accountNumber;
          cout << "Enter beginning balance: " << endl;
          cin >> beginningBalance;
          cout << "Enter total charges: " << endl;
          cin >> totalCharges;
          cout << "Enter total credit: " << endl;
          cin >> totalCredits;
          cout << "Enter credit limit: " << endl;
          cin >> creditLimit;
    
             if ( balance >= creditLimit ) {
                cout << "Account: " << accountNumber << endl;
                cout << "Credit limit: " << creditLimit << endl;
                cout << "Balance: " << balance << endl;
                cout << "Credit Limit Exceeded" << endl;
             }
    
             else
                cout << "Enter beginning balance: " << endl;
                cin >> beginningBalance;
                cout << "Enter total charges: " << endl;
                cin >> totalCharges;
                cout << "Enter total credit: " << endl;
                cin >> totalCredits;
                cout << "Enter credit limit: " << endl;
                cin >> creditLimit;
    
       }
    
       getch();
       return 0;
    }
    This doesn't produce any results, it just keeps asking me to enter a beginning balance, eventhough I have exceeded the credit limit.
    I thought didn't need to write a termination phase because there is no overall total to calculate.
    I have initialised the balance algorithm, but it might not be in the correct place? but I assume the if statement is written corretly?

  2. #2
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    You are missing the curly braces around the block of code after the else:
    Code:
             else {
                cout << "Enter beginning balance: " << endl;
                cin >> beginningBalance;
                cout << "Enter total charges: " << endl;
                cin >> totalCharges;
                cout << "Enter total credit: " << endl;
                cin >> totalCredits;
                cout << "Enter credit limit: " << endl;
                cin >> creditLimit;
             }

  3. #3
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,156

    Re: My credit limit program doesn't produce the desired output

    Originally posted by Guti14
    Code:
    #include<iostream>
    #include<conio>
    #include<iomanip>
    using namespace std;
    
    int main(int argc, char* argv[])
    {
       int      accountNumber;
       double   beginningBalance;
       double   totalCharges;
       double   totalCredits;
       double   creditLimit;
       double   balance;
    
    What is the value of beginningBalance, totalCharges, and totalCredits
    at this point of the program? Is this the best place for the calculation?
       balance = beginningBalance + totalCharges - totalCredits;
    
       cout << setprecision( 6 ) << fixed;
    
       while( accountNumber != -1 ) {
          cout << "Enter account Number: " << endl;
          cin >> accountNumber;
          cout << "Enter beginning balance: " << endl;
          cin >> beginningBalance;
          cout << "Enter total charges: " << endl;
          cin >> totalCharges;
          cout << "Enter total credit: " << endl;
          cin >> totalCredits;
          cout << "Enter credit limit: " << endl;
          cin >> creditLimit;
    
    What is the value of balance at this point in the code?
    You just did a bunch of inputs -- what do you plan on doing with 
    the information?
    
             if ( balance >= creditLimit ) {
                cout << "Account: " << accountNumber << endl;
                cout << "Credit limit: " << creditLimit << endl;
                cout << "Balance: " << balance << endl;
                cout << "Credit Limit Exceeded" << endl;
             }
    
             else
                cout << "Enter beginning balance: " << endl;
                cin >> beginningBalance;
                cout << "Enter total charges: " << endl;
                cin >> totalCharges;
                cout << "Enter total credit: " << endl;
                cin >> totalCredits;
                cout << "Enter credit limit: " << endl;
                cin >> creditLimit;
    
       }
    
       getch();
       return 0;
    }
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  4. #4
    Registered User
    Join Date
    Aug 2003
    Posts
    71
    Ok, Iv'e had another crack at it, but to no avail. Maybe I don't know where to put the right calculations and what I need to do with the input

    Code:
    #include<iostream>
    #include<conio>
    #include<iomanip>
    using namespace std;
    
    int main(int argc, char* argv[])
    {
       int      accountNumber;
       double   beginningBalance;
       double   totalCharges;
       double   totalCredits;
       double   creditLimit;
       double   x = 0;
       double   y = 0;
       double   balance;
    
       cout << setprecision( 6 ) << fixed;
    
       while( accountNumber != -1 ) {
          cout << "Enter account Number: " << endl;
          cin >> accountNumber;
    
          if( accountNumber != -1) {
          cout << "Enter beginning balance: " << endl;
          cin >> beginningBalance;
          cout << "Enter total charges: " << endl;
          cin >> totalCharges;
          cout << "Enter total credit: " << endl;
          cin >> totalCredits;
          cout << "Enter credit limit: " << endl;
          cin >> creditLimit;
    
          x = beginningBalance + totalCharges;
          y = x - totalCredits;
          balance = y;
    
          if ( balance > creditLimit ) {
                cout << "Account: " << accountNumber << endl;
                cout << "Credit limit: " << creditLimit << endl;
                cout << "Balance: " << balance << endl;
                cout << "Credit Limit Exceeded" << endl;
             }
          }
       }
       getch();
       return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 01:42 AM
  2. HELP with Program!
    By afnitti in forum C Programming
    Replies: 9
    Last Post: 04-15-2009, 08:06 PM
  3. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 02:30 PM
  4. Program Output
    By lavon in forum C Programming
    Replies: 1
    Last Post: 03-19-2002, 09:30 PM
  5. program output is empty!!!
    By ayesha in forum C++ Programming
    Replies: 4
    Last Post: 10-15-2001, 10:42 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21