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:

#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;
}

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.

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.

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.

You are kidding, right?

Kidding about what? I don't understand what you mean. Let's look at what Lerner said:

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.

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.

I don't see any arrays as called for in the instructions.

You can't pass if you don't follow the instructions.

I don't see any functions as called for in 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.

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.

Member Avatar for iamthwee

> 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. :)

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

if (lateFee = N)

be

if (lateFee == N)

?

boB

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.

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?

>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?

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

I enjoy working with computers very much. I am not a big fan of writing programming. As far as programming things and making them work better, that is a horse of a different color. For instance, reprogramming a router or setting up a network, or even writing macros for programs such as autocad or bentley, not that is my cup of tea. I am more into making programs that already exist run better and maximizing their output. Starting from scratch and writing a program is not my cup of tea. I appreciate those that do, but I dont have the patience to set and read code all day.

Almost finished! Here is what I have so far:

// reading a text file
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;

// Declaration for minimum payment function
double minimumPay(double);
double newBal(double, double, double, double);

int main () 
{
    // Setup your balance and open the credit card file
    double balanceline = 0.0;
    double lateFee = 0.0;
    double APR, newbalance, minimumPayment; 
    char ID[5];
    string line;
    ifstream myfile;
    cout << setprecision(2) << fixed << showpoint;

    // Open the file and start looping through it.
    myfile.open("cardholders1.txt");
    {
        while( myfile >> ID >> balanceline >> APR)
        {

            // Read in the customer ID from the file
            
            
            // Read in the balance from the file
           
            
      
            // Pass that balance to our function to find minimum payment
            minimumPayment = minimumPay(balanceline);
            newbalance = newBal(minimumPayment, balanceline, lateFee, APR);

            // Print out the balance and the minimum payment we figured out
            cout << "Customer ID: " << ID << endl;
            cout << "Balance is: " << balanceline << endl;
            cout << "Annual Percentage Rate: " << APR << endl;
            cout << "Minimum Payment: " << minimumPayment << endl;
            // Here we go on to asking for customer payment and if it was late
            // We call a function to calculate the fee
            // Then call our newBalance function to get the new balance
        }
        myfile.close();
    }

    

    
    return 0;
}

// This function figures out their minimum payment based on their balance.
double minimumPay(double balance) {
      double minimumPayment = 0.0;

      if (balance < 10.00) { minimumPayment = balance; }
      else {
            if ((balance * .15) > 10.00) { minimumPayment = balance * .15; }
            else { minimumPayment = 10.00; }
      }
      return minimumPayment;
system("PAUSE");
    
}
// This function figures out the late fee based on their balance.
    double minimumPayment(double balance) {
    double minimumPayment = 0.0;
    char YorN;
    double balanceline = 0.0;
    cout << "Was payment late, Please Enter Y or N:";
        cin >> YorN;
      
            if(YorN == 'Y' || YorN == 'y')
            {   if (balanceline <= 40)
                cout << "Your minimum payment is: $" << minimumPayment + 15 << endl;
                else if (balanceline >= 40 && balanceline <= 100)
                cout << "Your minimum payment is: $" << minimumPayment + 30 << endl;
                else if (balanceline > 100)
                cout << "Your minimum payment is: $" << minimumPayment + 45 << endl;
            }
      
            else if(YorN == 'N' || YorN == 'n')
            
            cout << "Your minimum payment is: $" << minimumPayment << endl;
            
      
system("PAUSE");
}    

double newBal(double minimumPayment, double balanceline, double lateFee, double APR)
      {
      if (balanceline - minimumPayment <= 0)
            double newBal;
      
      else newBal = (balanceline - minimumPayment) * APR) + lateFee;
            
       return newBal;
system("PAUSE");
}

I get error on line 102. Probably something simple, isnt it?

You have missed a opening bracket in line 102. else newBal = ((balanceline - minimumPayment) * APR) + lateFee;

Please explain these errors...

Compiler: Default compiler
Executing g++.exe...

cpp: In function `double newBal(double, double, double, double)':
cpp:101: error: assignment of function `double newBal(double, double, double, double)'

cpp:101: error: cannot convert `double' to `double ()(double, double, double, double)' in assignment

cpp:103: error: cannot convert `double (*)(double, double, double, double)' to `double' in return

Execution terminated

And how do I fix?

The function you posted is incorrect. Below is the correction, but the if statement may be wrong. You have to declare newBal at the top of the function so that it has scope in the entire function.

double newBal(double minimumPayment, double balanceline, double lateFee, double APR)
      {
           double newBal = 0;
      if (balanceline - minimumPayment <= 0)
            newBal = 1; // TODO:  Correct this statement!
      
      else newBal = ((balanceline - minimumPayment) * APR) + lateFee;
            
       return newBal;
system("PAUSE");
}

Thank you. Well, its at least working. Sort of. Window wont stay open, but it is working.

To keep the window open after completing the program put in something like this on line 54:

cin.get();

or something like this;

char ch;
cin >> ch;

or, if you must, something like this:

system("PAUSE");

To keep the window open after completing the program put in something like this on line 54:

...

system("PAUSE");

No. NEVER!!! :icon_rolleyes: Here's why!

Member Avatar for iamthwee

I think Lerner is well aware of the problems associated with system("pause") .

I wouldn't say 'never' use it. Sometimes, it is more important for a newbie to just get their program working than having to worry about the difficulties of clearing the input streams.

But yes in the long term, it's good to know how to do it the proper way.

I think Lerner is well aware of the problems associated with system("pause") .

Then he should know better.

I wouldn't say 'never' use it. Sometimes, it is more important for a newbie to just get their program working than having to worry about the difficulties of clearing the input streams.

I would. Aren't newbies taught cin ? If so, why teach them another command? One that's not a good command to use? I stand by my statement.

commented: Congratulations, you have just been promoted to Captain Retard! +13
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.