943,415 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 5708
  • C++ RSS
Feb 22nd, 2003
0

frustrated newbie needs help

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
fastcarz3 is offline Offline
7 posts
since Feb 2003
Feb 22nd, 2003
0
Re: frustrated newbie needs help
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:
C++ Syntax (Toggle Plain Text)
  1. int enterInfo=0;
  2. while (enterInfo<5) {x++};

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:

C++ Syntax (Toggle Plain Text)
  1. do
  2. {
  3. int account;
  4. float startBalance, endBalance, allowed, credits, charges;
  5.  
  6. cout << "Enter account #: ";
  7. cin >> account;
  8.  
  9. cout << "Enter credits applied to account: ";
  10. cin >> credits;
  11.  
  12. cout << "Enter credit card charges: ";
  13. cin >> charges;
  14.  
  15. cout << "Enter starting balance owed: ";
  16. cin >> startBalance;
  17.  
  18. cout << "Credit limit?: ";
  19. cin >> allowed;
  20.  
  21. endBalance = startBalance + charges - credits;
  22. if (endBalance > allowed)
  23. cout << "Credit limit exceeded";
  24. }
  25. while (account != -1)
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 162
The Queen of DaniWeb
cscgal is offline Offline
13,645 posts
since Feb 2002
Feb 22nd, 2003
0
Re: frustrated newbie needs help
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.
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 162
The Queen of DaniWeb
cscgal is offline Offline
13,645 posts
since Feb 2002
Feb 23rd, 2003
0
Re: frustrated newbie needs help
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.


C++ Syntax (Toggle Plain Text)
  1. bool moreCustomers=true;
  2. // step 1
  3. while(moreCustomers==true)
  4. {
  5. // step 2.1
  6. cout << "Enter the account number: " << flush;
  7. int accountNumber;
  8. cin >> accountNumber;
  9.  
  10. // step 2.2
  11. cout << "Enter the balance at start of month: " << flush;
  12. double startBalance;
  13. cin >> startBalance;
  14.  
  15. // step 2.3
  16. cout << "Enter the total monthly charges: " << flush;
  17. double monthlyCharge;
  18. cin >> monthlyCharge;
  19.  
  20. // step 2.4
  21. cout << "Enter the total monthly credits: " << flush;
  22. double monthlyCredit;
  23. cin >> monthlyCredit;
  24.  
  25. // step 2.5
  26. cout << "Enter the credit limit: " << flush;
  27. double creditLimit;
  28. cin >> creditLimit;
  29.  
  30. // step 3
  31. double newBalance = startBalance-monthlyCharge+monthlyCredit;
  32.  
  33. // step 4
  34. if(newBalance > creditLimit){
  35.  
  36. // step 5.1
  37. cout << "Account number: " << accountNumber << endl;
  38.  
  39. // step 5.2
  40. cout << "Credit limit: " << creditLimit << endl;
  41.  
  42. // step 5.3
  43. cout << "New balance: " << newBalance << endl;
  44.  
  45. // step 5.4
  46. cout << "Credit limit exceeded" << endl;
  47.  
  48. // step 6
  49. }
  50.  
  51. // step 7.1
  52. cout << "Another? " << flush;
  53. char yesNo;
  54. cin >> yesNo;
  55. if(yesNo != 'y'){
  56. moreCustomers=false;
  57. }
  58.  
  59. // step 7.2
  60. }

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.
Bob
Team Colleague
Reputation Points: 15
Solved Threads: 2
Junior Poster
Bob is offline Offline
129 posts
since Feb 2003
Mar 3rd, 2007
-1

Re: frustrated newbie needs help

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
Reputation Points: 9
Solved Threads: 0
Newbie Poster
Need_help! is offline Offline
5 posts
since Mar 2007
Mar 3rd, 2007
0

Re: frustrated newbie needs help

Perhaps you should ask your question with a new thread in the VB forum instead of resurrecting a four year old C++ thread. kthnxbye.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
May 10th, 2007
0

Re: frustrated newbie needs help

Click to Expand / Collapse  Quote originally posted by cscgal ...
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.
Reputation Points: 10
Solved Threads: 0
Light Poster
nkhosinathie is offline Offline
30 posts
since May 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in C++ Forum Timeline: someone please help
Next Thread in C++ Forum Timeline: Hey, I got a very simple program here. Yet the compiler is disagreeing with me.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC