| | |
frustrated newbie needs help
![]() |
•
•
Join Date: Feb 2003
Posts: 7
Reputation:
Solved Threads: 0
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
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
0
#2 Feb 22nd, 2003
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:
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:
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)
int enterInfo=0; 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)
do { int account; float startBalance, endBalance, allowed, credits, charges; cout << "Enter account #: "; cin >> account; cout << "Enter credits applied to account: "; cin >> credits; cout << "Enter credit card charges: "; cin >> charges; cout << "Enter starting balance owed: "; cin >> startBalance; cout << "Credit limit?: "; cin >> allowed; endBalance = startBalance + charges - credits; if (endBalance > allowed) cout << "Credit limit exceeded"; } while (account != -1)
0
#3 Feb 22nd, 2003
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.
•
•
Join Date: Feb 2003
Posts: 129
Reputation:
Solved Threads: 1
0
#4 Feb 23rd, 2003
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.
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.
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)
bool moreCustomers=true; // step 1 while(moreCustomers==true) { // step 2.1 cout << "Enter the account number: " << flush; int accountNumber; cin >> accountNumber; // step 2.2 cout << "Enter the balance at start of month: " << flush; double startBalance; cin >> startBalance; // step 2.3 cout << "Enter the total monthly charges: " << flush; double monthlyCharge; cin >> monthlyCharge; // step 2.4 cout << "Enter the total monthly credits: " << flush; double monthlyCredit; cin >> monthlyCredit; // step 2.5 cout << "Enter the credit limit: " << flush; double creditLimit; cin >> creditLimit; // step 3 double newBalance = startBalance-monthlyCharge+monthlyCredit; // step 4 if(newBalance > creditLimit){ // step 5.1 cout << "Account number: " << accountNumber << endl; // step 5.2 cout << "Credit limit: " << creditLimit << endl; // step 5.3 cout << "New balance: " << newBalance << endl; // step 5.4 cout << "Credit limit exceeded" << endl; // step 6 } // step 7.1 cout << "Another? " << flush; char yesNo; cin >> yesNo; if(yesNo != 'y'){ moreCustomers=false; } // step 7.2 }
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.
![]() |
Similar Threads
- Desktop & Taskbar on & off consistently (Windows NT / 2000 / XP)
- Frustrated Newbie!! (Visual Basic 4 / 5 / 6)
Other Threads in the C++ Forum
- Previous Thread: someone please help
- Next Thread: Hey, I got a very simple program here. Yet the compiler is disagreeing with me.
| Thread Tools | Search this Thread |
api array asterisks based binary bitmap c++ c/c++ char class classes code coding compile console conversion count delete deploy desktop developer directshow dissertationtopic dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer interest java knowledge languagerosettastone lib linkedlist linker loop looping loops map math matrix memory msuhangman multiple news node nodes objects output pointer polynomial problem program programming project python random read recursion reference rpg space stop string strings temperature template test text text-file tree url variable vector video warcraft3 win32 windows winsock wordfrequency wxwidgets






