Develop a C++ program that will determine whether a department-store customer has ex-ceeded 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 customers account this month
e. allowed credit limit


The program should use a while structure 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 customers account number, credit limit, new balance and the message "Credit Limit exceeded".

If anyone could hook me up with the solution it would save me from going crazy

Recommended Answers

All 6 Replies

You say that for each customer a bunch of info is available. Is this info stored as a struct or a class? (I don't know if you're familiar at all with object oriented programming. If not, just ignore this question b/c it won't make much sense to you.)

I don't see how you would use a while loop to input those five properties of the user.

Perhaps:

int enterInfo=0;
while &#40;enterInfo<5&#41; &#123;x++&#125;;

That doesn't make much sense to me though. Perhaps the program deals with one user after another, and it loops in a while loop until account number is -1 or something? Here's a quick sketch of doing it that way:

do
&#123;
     int account;
     float startBalance, endBalance, allowed, credits, charges;

     cout << "Enter account #&#58; ";
     cin >> account;

     cout << "Enter credits applied to account&#58; ";
     cin >> credits;

     cout << "Enter credit card charges&#58; ";
     cin >> charges;

     cout << "Enter starting balance owed&#58; ";
     cin >> startBalance;

     cout << "Credit limit?&#58; ";
     cin >> allowed;

     endBalance = startBalance + charges - credits;
     if &#40;endBalance > allowed&#41;
          cout << "Credit limit exceeded";
&#125;
while &#40;account != -1&#41;

Once again, I'm not sure if this is what you're looking for. Maybe someone else would be able to give you a hand here in the forums. Otherwise, drop me an IM via AIM.

Dani has already provided the basis of a solution. I think it's equally as important to understand *how* you come up with a solution to problems such as this. You need an approach to problem solving.

There's no rocket science involved; you simply need to go through your problem statement, break it down into steps, refine the steps, then implement those steps as C++ code. Let's work it through.

We know from the first paragraph that our program is going to deal with customers, multiple customers, and that for each the following information is required:

Account Number
Balance at start of month
Total monthly charge
Total monthly credits
Credit limit

We can already envisage the use of variables for these, e.g.

int accountNumber;
double startBalance;
double monthlyCharge;
double monthlyCredit;
double creditLimit;

but that's a level of detail that we don't need to worry about yet.

In the second paragraph it says we should use a while structure to input those values, calculate the new balance, check if the credit limit has been exceeded, if it has display the customer details and a warning message. This paragraph describes the steps we need, so let's list them, it will form the basis of our solution (Stage 1):

1. Loop while we have more customers
2. Read in the customer details
3. Calculate the customer's new account balance
4. If the limit has been exceeded
5. Output the customer account details and warning message
6. end if
7. end loop

That's a very simple form of pseudocode, in English. A basic design, if you like, for our solution.

Now we refine those steps a little in Stage 2:

1. Loop while we have more customers
2.1 Input the Account Number
2.2 input the balance at start of month
2.3 Input the total monthly charge
2.4 Input the total monthly credit
2.5 Input the credit limit
3. Set new balance to start balance - charges + credits
4. If new balance is greater than credit limit
5.1 Output account number
5.2 Output credit limit
5.3 Output new balance
5.4 Output "Credit Limit Exceeded"
6. End if
7.1 Prompt for more customers
7.2 End loop

We can refine a number of these steps further, Stage 3, for example:

2.1 Input account number

becomes:

2.1.1 Prompt for account number
2.1.2 Read in account number

and so on. We may refine some steps several more times (and others not at all). Once we have refined these steps sufficiently we start to translate them to code (Stage 4). Here's an example that matches the steps above, with some implementation tweaks.

bool moreCustomers=true;
// step 1
while&#40;moreCustomers==true&#41;
&#123;
    // step 2.1
    cout << "Enter the account number&#58; " << flush;
    int accountNumber;
    cin >> accountNumber;

    // step 2.2
    cout << "Enter the balance at start of month&#58; " << flush;
    double startBalance;
    cin >> startBalance;

    // step 2.3
    cout << "Enter the total monthly charges&#58; " << flush;
    double monthlyCharge;
    cin >> monthlyCharge;

    // step 2.4
    cout << "Enter the total monthly credits&#58; " << flush;
    double monthlyCredit;
    cin >> monthlyCredit;

    // step 2.5
    cout << "Enter the credit limit&#58; " << flush;
    double creditLimit;
    cin >> creditLimit;

    // step 3
    double newBalance = startBalance-monthlyCharge+monthlyCredit;

    // step 4
    if&#40;newBalance > creditLimit&#41;&#123;

        // step 5.1
        cout << "Account number&#58; " << accountNumber << endl;
        
        // step 5.2
        cout << "Credit limit&#58; " << creditLimit << endl;
 
        // step 5.3
        cout << "New balance&#58; " << newBalance << endl;

        // step 5.4
        cout << "Credit limit exceeded" << endl;

    // step 6
    &#125;

    // step 7.1
    cout << "Another? " << flush;
    char yesNo;
    cin >> yesNo;
    if&#40;yesNo != 'y'&#41;&#123;
        moreCustomers=false;
    &#125;

// step 7.2
&#125;

That's a simplified approach (and the code hasn't been tested, it's the approach that matters) but you get the idea. It's really a question of designing the solution before you code it. Can you see how the design was taken straight from the problem statement and broken down into simple steps, then refined, then coded?

Later you'll want to use more sophisticated design techniques, but this should help you to understand how to tackle new problems, even if you don't have a clue how to code it at the start.

By the way, using this method you might find that you can code 4 or 5 of the steps yourself but that, for instance, the remaining steps are unclear to you because you're still learning. You can then post the code you have and people will help you with the gaps.

Good luck.

hey i have that same problem except mine is in VB and i can't seem to get it neither!!! im sooo FRUSTRATED i see the logic but it is hard to decipher into VB text

commented: Well you could start by picking the right forum -1

Perhaps you should ask your question with a new thread in the VB forum instead of resurrecting a four year old C++ thread. kthnxbye.

Once again, I'm not sure if this is what you're looking for. Maybe someone else would be able to give you a hand here in the forums. Otherwise, drop me an IM via AIM.

hello i'm so happy to tell u that u have already helped me,i was looking for that program about a department-store customer program, but my question is what if i don't use that if statement.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.