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?
Re: My credit limit program doesn't produce the desired output
Quote:
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;
}