943,962 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2223
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Dec 1st, 2007
0

Almost Got It, I think

Expand Post »
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:
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <fstream>
  4. using namespace std;
  5.  
  6. int main ()
  7.  
  8. {
  9. ifstream inFile;
  10. int custID, newBal, intRate;
  11. cout.precision(2);
  12. inFile.open("cardholders.txt");
  13. cout << "Reading information from the file.\n\n";
  14.  
  15. inFile >> custID;
  16. inFile >> newBal;
  17. inFile >> intRate;
  18.  
  19. {
  20. // Make sure we use types that hold decimal places
  21. double custID, minPay, curBal, newBal, lateFee, intRate, Y, N;
  22.  
  23. cout << "What is your current balance:";
  24. cin >> curBal;
  25. if (curBal<10.00)
  26. minPay = curBal;
  27. else (curBal>10.00);
  28. minPay = curBal * 0.15;
  29.  
  30. cout << "Was payment late:";
  31. cin >> Y or N;
  32. if (lateFee = N)
  33. lateFee = minPay;
  34.  
  35. else (lateFee = Y);
  36. }
  37. else (curBal < 40)
  38. minPay = minPay + 15;
  39. else (curBal > 40 && < 100)
  40. minPay = minPay + 30;
  41. else (curBal > 100)
  42. minPay = minPay + 45;
  43. return 0;
  44. }
  45. {
  46. cout << "Enter current balance:";
  47. cin >> curBal;
  48. cout<<" Enter Late Fee:";
  49. cin >> lateFee;
  50. cout << "Enter Current Payment:";
  51. cin >> minPay;
  52. cout << "New Balance is:";
  53. cout << (curBal + lateFee) - minPay << endl;
  54.  
  55.  
  56. cout << "File written to, and now being closed..." << endl;
  57.  
  58. outputFile.close();
  59. cout << "Done.\n";
  60.  
  61. {
  62. {
  63. ifstream inFile;
  64. int custID, newBal, intRate;
  65. inFile.open("cardholders.txt");
  66. cout << "Reading information from the file.\n\n";
  67.  
  68. inFile >> custID;
  69. inFile >> newBal;
  70. inFile >> intRate;
  71.  
  72. // Process Customer 1
  73. inFile >> custID;
  74. inFile >> newBal;
  75. inFile >> intRate;
  76. cout << "Customer ID 1: " << newBal << intRate << endl;
  77.  
  78. // Process Customer 2
  79. inFile >> custID;
  80. inFile >> newBal;
  81. inFile >> intRate;
  82. cout << "Customer ID 2: " << newBal << intRate << endl;
  83.  
  84. // Process Customer 3
  85. inFile >> custID;
  86. inFile >> newBal;
  87. inFile >> intRate;
  88. cout << "Customer ID 3: " << newBal << intRate << endl;
  89.  
  90. // Process Customer 4
  91. inFile >> custID;
  92. inFile >> newBal;
  93. inFile >> intRate;
  94. cout << "Customer ID 4: " << newBal << intRate << endl;
  95.  
  96. // Process Customer 5
  97. inFile >> custID;
  98. inFile >> newBal;
  99. inFile >> intRate;
  100. cout << "Customer ID 5: " << newBal << intRate << endl;
  101.  
  102. // Close the file
  103. inFile.close();
  104. cout << "\nDone.\n";
  105.  
  106. system("PAUSE");
  107. return 0;
  108. }
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.
Attached Files
File Type: txt cardholders.txt (66 Bytes, 11 views)
Last edited by cscgal; Dec 1st, 2007 at 8:29 pm. Reason: Added code tags
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Dean_X is offline Offline
10 posts
since Dec 2007
Dec 1st, 2007
0

Re: Almost Goy It, I think

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.
Reputation Points: 718
Solved Threads: 373
Nearly a Posting Maven
Lerner is offline Offline
2,253 posts
since Jul 2005
Dec 1st, 2007
0

Re: Almost Goy It, I think

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Dean_X is offline Offline
10 posts
since Dec 2007
Dec 2nd, 2007
0

Re: Almost Goy It, I think

Click to Expand / Collapse  Quote originally posted by Dean_X ...
You are kidding, right?
Kidding about what? I don't understand what you mean. Let's look at what Lerner said:
Click to Expand / Collapse  Quote originally posted by Lerner ...
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.
You want help but don't want to make your code readable? Why not write it in Swahili then.

Click to Expand / Collapse  Quote originally posted by Lerner ...
I don't see where you declare outfile at all, so trying to close it is definitely a no-no.
This is a definite error in your code. It can't run correctly without it.

Click to Expand / Collapse  Quote originally posted by Lerner ...
I don't see any arrays as called for in the instructions.
You can't pass if you don't follow the instructions.

Click to Expand / Collapse  Quote originally posted by Lerner ...
I don't see any functions as called for in the instructions.
You can't pass if you don't follow the instructions.

Click to Expand / Collapse  Quote originally posted by Lerner ...
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.
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.
Moderator
Reputation Points: 3278
Solved Threads: 894
Posting Sage
WaltP is online now Online
7,744 posts
since May 2006
Dec 2nd, 2007
0

Re: Almost Goy It, I think

> 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 #include "verySmallViolins" your teacher just might pass you on the grounds of sympathy.
Last edited by iamthwee; Dec 2nd, 2007 at 7:50 am.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Dec 2nd, 2007
0

Re: Almost Goy It, I think

I'm not trying to sound like a prick here, but shouldn't

if (lateFee = N)

be

if (lateFee == N)

?

boB
Reputation Points: 10
Solved Threads: 1
Newbie Poster
boB_K7IQ is offline Offline
4 posts
since Dec 2007
Dec 2nd, 2007
0

Re: Almost Goy It, I think

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.
Moderator
Reputation Points: 3278
Solved Threads: 894
Posting Sage
WaltP is online now Online
7,744 posts
since May 2006
Dec 2nd, 2007
0

Re: Almost Goy It, I think

I already did that. I pasted my entire assignment in my first post. I pasted my code and the errors I received. All I got was, "your code is wrong." Isnt that the whole point in bringing my problem to this forum. If my code was right, I wouldnt need to post it, now would I?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Dean_X is offline Offline
10 posts
since Dec 2007
Dec 2nd, 2007
0

Re: Almost Goy It, I think

>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?
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Dec 2nd, 2007
0

Re: Almost Goy It, I think

Since you say you are not interested in how the program works, I can only assume that you
really aren't interested in the subject of computers and IT very much. Because of that,
you may not last long in this industry. I wouldn't hire anyone that didn't like their job.

boB
Reputation Points: 10
Solved Threads: 1
Newbie Poster
boB_K7IQ is offline Offline
4 posts
since Dec 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.
Message:
Previous Thread in C++ Forum Timeline: Function for getting the language code in standard library
Next Thread in C++ Forum Timeline: int to roman numeral help





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


Follow us on Twitter


© 2011 DaniWeb® LLC