Develop a C++ program that will determine whether a depart- ment-store customer has exceeded the credit limit on a charge account. For each customer, the following facts are available:

a) Account number (an integer)
b) Balance at the beginning of the month
c) Total of all items charged by this customer this month
d) Total of all credits applied to this customer's account this month
e) Allowed credit limit
The program should use a while statement to input each of these facts, calculate the new balance (= beginning balance + charges – credits) and determine whether the new balance exceeds the customer’s credit limit. For those customers whose credit limit is exceeded, the program should display the customer's account number, credit limit, new balance and the message “Credit Limit Exceeded.”

Enter account number (or -1 to quit): 100
Enter beginning balance: 5394.78
Enter total charges: 1000.00
Enter total credits: 500.00
Enter credit limit: 5500.00
New balance is 5894.78
Account: 100
Credit limit: 5500.00
Balance: 5894.78
Credit Limit Exceeded.
Enter Account Number (or -1 to quit): 200
Enter beginning balance: 1000.00
Enter total charges: 123.45
Enter total credits: 321.00
Enter credit limit: 1500.00
New balance is 802.45
Enter Account Number (or -1 to quit): 300
Enter beginning balance: 500.00
Enter total charges: 274.73
Enter total credits: 100.00
Enter credit limit: 800.00
New balance is 674.73
Enter Account Number (or -1 to quit): -1

Top:
Determine if each of an arbitrary number of department store customers has exceeded
the credit limit on a charge account
First refinement:
Input customer’s data
For each customer, calculate and display the customer’s new balance, and display a
message if user’s balance exceeds credit limit
Process next customer
Second refinement:
Prompt the user for the first customer’s account number
Input the first customer’s account number
While the sentinel value (-1) has not been entered for the account number
Prompt the user for the customer’s beginning balance
Input the customer’s beginning balance
Prompt the user for the customer’s total charges
Input the customer’s total charges
Prompt the user for the customer’s total credits
Input the customer’s total credits
Prompt the user for the customer’s credit limit
Input the customer’s credit limit
Calculate and display the customer’s new balance
If the balance exceeds the credit limit
Print the account number
Print the credit limit
Print the balance
Print “Credit Limit Exceeded”
Input the next customer’s account number

```
// Calculate credit balances.
#include
#include // parameterized stream manipulators
using namespace std;

int main()
{
int account; // account number
double balance; // account balance
double charges; // total charges
double credits; // total credits
double creditLimit; // allowed credit limit

cout << "Enter account number (or -1 to quit): ";
cin >> account; // read in account number

// set floating-point number format
cout << fixed << setprecision( 2 );

// exit if the input is -1; otherwise, proceed with the program
while ( account != -1 )
{
cout << "Enter beginning balance: ";
cin >> balance; // read in original balance

cout << "Enter total charges: ";
cin >> charges; // read in charges

cout << "Enter total credits: ";
cin >> credits; // read in credits

cout << "Enter credit limit: ";
cin >> creditLimit; // read in credit limit

// calculate and display new balance
balance = balance + charges - credits;
cout << "New balance is " << balance;

// display a warning if the user has exceed the credit limit
if ( balance > creditLimit )
cout << "\nAccount: " << account
<< "\nCredit limit: " << creditLimit
<< "\nBalance: " << balance
<< "\nCredit Limit Exceeded.";

cout << "\n\nEnter Account Number (or -1 to quit): ";
cin >> account; // read in next account number
} // end while
} // end main
```
Enter account number (or -1 to quit): 100
Enter beginning balance: 5394.78
Enter total charges: 1000.00
Enter total credits: 500.00
Enter credit limit: 5500.00
New balance is 5894.78
Account: 100
Credit limit: 5500.00
Balance: 5894.78
Credit Limit Exceeded.
Enter Account Number (or -1 to quit): 200
Enter beginning balance: 1000.00
Enter total charges: 123.45
Enter total credits: 321.00
Enter credit limit: 1500.00
New balance is 802.45
Enter Account Number (or -1 to quit): 300
Enter beginning balance: 500.00
Enter total charges: 274.73
Enter total credits: 100.00
Enter credit limit: 800.00
New balance is 674.73
Enter Account Number (or -1 to quit): -1

Computer Science & Information Technology

You might also like to view...

Inserting graphic in a table cell may cause the column width and row height to be modified

Indicate whether the statement is true or false

Computer Science & Information Technology

TheselectorTextproperty can only be used to read the text of a Cascading Style Sheets (CSS) rule.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology