(Credit Limits) Develop a C++ program that will determine whether a department store customer has exceeded the credit limit on a charge account. For each customer, the following facts are available:
Enter account number (or 1 to quit): 1 00
Enter beginning balance: 5394.78
Enter total charges: 1 000.00
Enter total credits: 500.00
Enter credit limit: 5500.00
New balance is 5894.78
Account: 1 00
Credit limit: 5500.00
Balance: 5894.78
Credit Limit Exceeded.
Enter Account Number (or 1 to quit): 200
Enter beginning balance: 1 000.00
Enter total charges: 1 23.45
Enter total credits: 321 .00
Enter credit limit: 1 500.00
New balance is 802.45
Enter Account Number (or 1 to quit): 1
#include
#include
using namespace std;
int main()
{
double totalChargesMonth = 0;
double totalCreditsMonth = 0;
int accountNumber;
double initialBalance;
double availableCredit;
double newBalance;
cout << "Enter account number (or ‐1 to quit) : ";
cin >> accountNumber;
while( accountNumber ! = ‐1)
{
cout << "Enter beginning balance: ";
cin >> initialBalance;
cout << "Enter total charges: ";
cin >> totalChargesMonth;
cout << "Enter total credits: ";
cin >> totalCreditsMonth;
cout << "Enter credit limit: ";
cin >> availableCredit;
newBalance = (initialBalance + totalChargesMonth ‐ totalCreditsMonth) ;
if ( newBalance > availableCredit)
{
cout << "\nNew balance is " << newBalance << endl;
J
cout << "Account: " << accountNumber << endl;
cout << "Credit limit: " << availableCredit << endl;
cout << "Balance: " << newBalance << endl;
cout << "Credit Limit Exceeded. " << endl;
}
else
{
cout << "\nNew balance is " << newBalance << endl;
}
cout << "Enter account number (or ‐1 to quit) : ";
cin >> accountNumber;
}
//for pause
system("PAUSE") ;
return 0;
}
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): 1 00
Enter beginning balance: 5394.78
Enter total charges: 1 000.00
Enter total credits: 500.00
Enter credit limit: 5500.00
New balance is 5894.78
Account: 1 00
Credit limit: 5500.00
Balance: 5894.78
Credit Limit Exceeded.
Enter Account Number (or 1 to quit): 200
Enter beginning balance: 1 000.00
Enter total charges: 1 23.45
Enter total credits: 321 .00
Enter credit limit: 1 500.00
New balance is 802.45
Enter Account Number (or 1 to quit): 1
Solution:
#include#include
#include
using namespace std;
int main()
{
double totalChargesMonth = 0;
double totalCreditsMonth = 0;
int accountNumber;
double initialBalance;
double availableCredit;
double newBalance;
cout << "Enter account number (or ‐1 to quit) : ";
cin >> accountNumber;
while( accountNumber ! = ‐1)
{
cout << "Enter beginning balance: ";
cin >> initialBalance;
cout << "Enter total charges: ";
cin >> totalChargesMonth;
cout << "Enter total credits: ";
cin >> totalCreditsMonth;
cout << "Enter credit limit: ";
cin >> availableCredit;
newBalance = (initialBalance + totalChargesMonth ‐ totalCreditsMonth) ;
if ( newBalance > availableCredit)
{
cout << "\nNew balance is " << newBalance << endl;
J
cout << "Account: " << accountNumber << endl;
cout << "Credit limit: " << availableCredit << endl;
cout << "Balance: " << newBalance << endl;
cout << "Credit Limit Exceeded. " << endl;
}
else
{
cout << "\nNew balance is " << newBalance << endl;
}
cout << "Enter account number (or ‐1 to quit) : ";
cin >> accountNumber;
}
//for pause
system("PAUSE") ;
return 0;
}
Please Make An Algorithm For It .
ReplyDelete