| | |
Almost Got It, I think
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2007
Posts: 10
Reputation:
Solved Threads: 0
Here is my problem. I have searched everywhere for help on this one. I haven't found any. So, I sat down and tried the best I could to write this code: Now I am stuck:
Here is what I have so far:
Heres is what I need it to do:
* The program should read all the records in the file cardholders.txt until the end of the file. Each cardholder record contains the customer ID, current balance, and APR.
* For each record read, the program should do the following:
• Calculate the minimum payment due for the next billing cycle. If the current balance is less than $10.00, then the minimum payment will be the current balance. Otherwise, the minimum payment will be the greater of $10.00 or 15% of the current balance.
• Ask the user to enter the amount of the current payment for the customer with this ID. Ask the user whether the payment was late.
• Calculate the late fee. If the payment was not late, there will be no late fee.
For late payments:
• If the current balance is less than $40, the late fee will be $15.
• If the current balance is in the range from $40 to $100, the late fee will be $30.
• If the current balance is over $100, the late fee will be $45.
• Use a function called NewBalance to calculate the customer’s new balance. (You must create this function.) The function NewBalance will accept the APR, late fee, current balance, and current payment as input parameters and return the customer’s new balance.
• Store the data for this customer in three parallel arrays, custID, newbal, and minpay. These three arrays should respectively hold each customer’s ID, new balance, and minimum payment.
After all the records in the cardholders.txt file have been processed, the program should display a report with three columns showing each customer’s ID, new balance, and minimum payment. The columns should be aligned appropriately. The new balance and minimum payment should be displayed in currency format with 2 fixed decimal places.
Where do I go from here? I am literally stuck.
Forgive me, but I am just trying to get through this without going nuts. I am an IT major. I have to take these classes as part of my core. I am almost done with all of it. I have been doing great up to this one and it is kicking my rear. I have been looking at code for what seems like an eternity. Unfortunately, I also had to take webpage class this semester and sometimes it seems the code from one runs on to the other. I am just trying to survive this class. I have an "A" in the class as of right now, but at this point I will settle for a "B". I am just frustrated with this whole thing.
Sorry for venting. Thanks for all of your help.
OK, now, how can you help me?
Oh, and btw, Can you run the 3 parrellel code for me with attached file? It is working but output is wrong.
Here is what I have so far:
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <iomanip> #include <fstream> using namespace std; int main () { ifstream inFile; int custID, newBal, intRate; cout.precision(2); inFile.open("cardholders.txt"); cout << "Reading information from the file.\n\n"; inFile >> custID; inFile >> newBal; inFile >> intRate; { // Make sure we use types that hold decimal places double custID, minPay, curBal, newBal, lateFee, intRate, Y, N; cout << "What is your current balance:"; cin >> curBal; if (curBal<10.00) minPay = curBal; else (curBal>10.00); minPay = curBal * 0.15; cout << "Was payment late:"; cin >> Y or N; if (lateFee = N) lateFee = minPay; else (lateFee = Y); } else (curBal < 40) minPay = minPay + 15; else (curBal > 40 && < 100) minPay = minPay + 30; else (curBal > 100) minPay = minPay + 45; return 0; } { cout << "Enter current balance:"; cin >> curBal; cout<<" Enter Late Fee:"; cin >> lateFee; cout << "Enter Current Payment:"; cin >> minPay; cout << "New Balance is:"; cout << (curBal + lateFee) - minPay << endl; cout << "File written to, and now being closed..." << endl; outputFile.close(); cout << "Done.\n"; { { ifstream inFile; int custID, newBal, intRate; inFile.open("cardholders.txt"); cout << "Reading information from the file.\n\n"; inFile >> custID; inFile >> newBal; inFile >> intRate; // Process Customer 1 inFile >> custID; inFile >> newBal; inFile >> intRate; cout << "Customer ID 1: " << newBal << intRate << endl; // Process Customer 2 inFile >> custID; inFile >> newBal; inFile >> intRate; cout << "Customer ID 2: " << newBal << intRate << endl; // Process Customer 3 inFile >> custID; inFile >> newBal; inFile >> intRate; cout << "Customer ID 3: " << newBal << intRate << endl; // Process Customer 4 inFile >> custID; inFile >> newBal; inFile >> intRate; cout << "Customer ID 4: " << newBal << intRate << endl; // Process Customer 5 inFile >> custID; inFile >> newBal; inFile >> intRate; cout << "Customer ID 5: " << newBal << intRate << endl; // Close the file inFile.close(); cout << "\nDone.\n"; system("PAUSE"); return 0; }
* The program should read all the records in the file cardholders.txt until the end of the file. Each cardholder record contains the customer ID, current balance, and APR.
* For each record read, the program should do the following:
• Calculate the minimum payment due for the next billing cycle. If the current balance is less than $10.00, then the minimum payment will be the current balance. Otherwise, the minimum payment will be the greater of $10.00 or 15% of the current balance.
• Ask the user to enter the amount of the current payment for the customer with this ID. Ask the user whether the payment was late.
• Calculate the late fee. If the payment was not late, there will be no late fee.
For late payments:
• If the current balance is less than $40, the late fee will be $15.
• If the current balance is in the range from $40 to $100, the late fee will be $30.
• If the current balance is over $100, the late fee will be $45.
• Use a function called NewBalance to calculate the customer’s new balance. (You must create this function.) The function NewBalance will accept the APR, late fee, current balance, and current payment as input parameters and return the customer’s new balance.
• Store the data for this customer in three parallel arrays, custID, newbal, and minpay. These three arrays should respectively hold each customer’s ID, new balance, and minimum payment.
After all the records in the cardholders.txt file have been processed, the program should display a report with three columns showing each customer’s ID, new balance, and minimum payment. The columns should be aligned appropriately. The new balance and minimum payment should be displayed in currency format with 2 fixed decimal places.
Where do I go from here? I am literally stuck.
Forgive me, but I am just trying to get through this without going nuts. I am an IT major. I have to take these classes as part of my core. I am almost done with all of it. I have been doing great up to this one and it is kicking my rear. I have been looking at code for what seems like an eternity. Unfortunately, I also had to take webpage class this semester and sometimes it seems the code from one runs on to the other. I am just trying to survive this class. I have an "A" in the class as of right now, but at this point I will settle for a "B". I am just frustrated with this whole thing.
Sorry for venting. Thanks for all of your help.
OK, now, how can you help me?
Oh, and btw, Can you run the 3 parrellel code for me with attached file? It is working but output is wrong.
Last edited by cscgal; Dec 1st, 2007 at 8:29 pm. Reason: Added code tags
•
•
Join Date: Jul 2005
Posts: 1,688
Reputation:
Solved Threads: 265
Your code is almost impossible to read due to poor formatting. Learning how to format with consistent and appropriate indentation will save you lots of time trying to debug and make it easier for others trying to help or trying to maintain your code.
I don't see where you declare outfile at all, so trying to close it is definitely a no-no.
I don't see any arrays as called for in the instructions.
I don't see any functions as called for in the instructions.
First thing I'd do is comment everything out of the code from this line down:
inFile >> intRate;
Then develop a loop to read the entire file, outputting at least one set of information to be sure you're reading it in correctly. Once you've got that you can proceed further.
I don't see where you declare outfile at all, so trying to close it is definitely a no-no.
I don't see any arrays as called for in the instructions.
I don't see any functions as called for in the instructions.
First thing I'd do is comment everything out of the code from this line down:
inFile >> intRate;
Then develop a loop to read the entire file, outputting at least one set of information to be sure you're reading it in correctly. Once you've got that you can proceed further.
•
•
Join Date: Dec 2007
Posts: 10
Reputation:
Solved Threads: 0
You are kidding, right? I am only doing this because I have to. As soon as I am done with this class I am done with programming. The main reason for this attitude is that I know a few people that are programmers. Outside of being good programmers, they are good for anything else. They are lousy teachers because they dont know how to get past their own arrogance. So, a far an really wanting to get to know this stuff, I will pass. I will do just enough to get my "A" and move on. Thank you.
Kidding about what? I don't understand what you mean. Let's look at what Lerner said:
You want help but don't want to make your code readable? Why not write it in Swahili then.
This is a definite error in your code. It can't run correctly without it.
You can't pass if you don't follow the instructions.
You can't pass if you don't follow the instructions.
A reasonable suggestion, so YOU can figure out what your code is doing.
So no, Lerner is not kidding. Are you saying that as an IT Major you don't need to learn any programming? This is news to me. Even so, we don't write code for people here, even if all they want to do is skate through their course without learning anything.
•
•
•
•
Your code is almost impossible to read due to poor formatting. Learning how to format with consistent and appropriate indentation will save you lots of time trying to debug and make it easier for others trying to help or trying to maintain your code.
•
•
•
•
I don't see where you declare outfile at all, so trying to close it is definitely a no-no.
You can't pass if you don't follow the instructions.
You can't pass if you don't follow the instructions.
•
•
•
•
First thing I'd do is comment everything out of the code from this line down:
inFile >> intRate;
Then develop a loop to read the entire file, outputting at least one set of information to be sure you're reading it in correctly. Once you've got that you can proceed further.
So no, Lerner is not kidding. Are you saying that as an IT Major you don't need to learn any programming? This is news to me. Even so, we don't write code for people here, even if all they want to do is skate through their course without learning anything.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
> I have an "A" in the class as of right now, but at this point I will settle for a "B".
In that case your teachers must be clowns and your school must actually be a circus, because at the moment all I see is a big attitude with no signs of intelligence at all.
> I already figured that one out. Jeez! It really sux when a
> person like me, in their 40's,
If you behave like this in your 40's then I would hate to have seen what you behaved like when you were younger.
> PS. My code doesnt work, just thought I would let you know.
Well duh! When you decide to actually put some of your own effort into this, drop the attitude and realise that these people here are giving up their free time to help you, you'll get all the help you'll need honey.
And I'll let you into a trade secret. If you include the header file
In that case your teachers must be clowns and your school must actually be a circus, because at the moment all I see is a big attitude with no signs of intelligence at all.
> I already figured that one out. Jeez! It really sux when a
> person like me, in their 40's,
If you behave like this in your 40's then I would hate to have seen what you behaved like when you were younger.
> PS. My code doesnt work, just thought I would let you know.
Well duh! When you decide to actually put some of your own effort into this, drop the attitude and realise that these people here are giving up their free time to help you, you'll get all the help you'll need honey.
And I'll let you into a trade secret. If you include the header file
#include "verySmallViolins" your teacher just might pass you on the grounds of sympathy.
Last edited by iamthwee; Dec 2nd, 2007 at 7:50 am.
*Voted best profile in the world*
Dean, please explain what was wrong with the first response you received? Lerner's assessment was right on. I guess my question is in your first post did you follow all the suggestions in the post titled Read Me: Read This Before Posting? If you can honestly say yes, we're sorry. If you can't, post a question that we have a reasonable chance of answering.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
>All I got was, "your code is wrong."
That's an exaggeration. You received help for figuring out what's wrong with your code as well as for helping us to help you more. Then you started whining about how we're pricks (probably because we didn't point out every single problem and fix it for you). Tell me this: why should you expect us to help you when you clearly don't respect us enough to listen?
That's an exaggeration. You received help for figuring out what's wrong with your code as well as for helping us to help you more. Then you started whining about how we're pricks (probably because we didn't point out every single problem and fix it for you). Tell me this: why should you expect us to help you when you clearly don't respect us enough to listen?
I'm here to prove you wrong.
![]() |
Other Threads in the C++ Forum
- Previous Thread: Function for getting the language code in standard library
- Next Thread: int to roman numeral help
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






