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 -
This doesn't produce any results, it just keeps asking me to enter a beginning balance, eventhough I have exceeded the credit limit.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; }
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?