Cant figure out whats wrong with code.
This is code should "write a program to compute the interest due, total amount due, and the minimum payment for a revolving credit account. The program accepts account balance as input from a file, then adds on the interest to get the total amount due."
Been try my best to make code but cant get rid of last two error.
Please help!!
Very new to c++ just started 4 months ago and still a novice.

The code is as follows:

#include <iostream>
#include <fstream> // I/O
#include <iomanip> // For setw()
using namespace std;

ofstream     outputfile("output.txt");     // Output file

const int MAX_FILE_NAME = 35;
const double INTEREST_RATE1 = 0.010;
const double INTEREST_RATE2 = 0.010;
const double LEVEL_ONE_BALANCE = 1000.00;
const double MINIMUM_PAYMENT = 10.00;
const double MINIMUM_PAYMENT_PERCENT = 0.10;



class Account
{
public:
Account( double Balance, double InterestRate1, double InterestRate2);
Account( );
double Payment();
double InterestDue();
double TotalAmountDue();
void output(ostream &out); // Print values on output stream out(); 

private:
double balance;
double interest;
double payment;
double interest_rate1;
double interest_rate2;
double total_amount_due;
}


void open_input(ifstream& input, char name[]);
void process_file(ifstream& input);

int main ()

{ 
char again;
char file_name[MAX_FILE_NAME + 1];
ifstream input_numbers;

cout << "This program calculates values\n"
    << "customer invoices.\n" << endl;
system("pause");

    do
    {
        system ("cls");
        open_input(input_numbers, file_name);
        process_file(input_numbers);
        input_numbers.close();

        cout << "\n Another File?" << endl;
        cin >> again;
        cin.ignore(256, '\n');  
    }
    while (again == 'y' || again == 'Y');


        cout << "\nEnd!!!!!" << endl;
        outputfile << "\nThanks for using program";
        outputfile.close();

        return 0;}

        void open_input (ifstream& input, char name[]);

        {
            int count = 0;

        do
        { count++; 
            if (count !=1)
            { cout << "\n\aInvalid file or it does not exist." << endl;

        }

        cout << "\nEnter the input file name,please. (maximum of " << MAX_FILE_NAME
            << " characters please)\n:>";
        cin.get(name, MAX_FILE_NAME + 1);
        cin.ignore(256, '\n');
        input.clear();
        input.open(name,ios_base::in);
        }
        while (input.fail() );
}

    void process_file(ifstream& input)

        {
            double value;

        Account thisAccount;
        while (input >> value)
        {
            thisAccount = Account (value, INTEREST_RATE1, INTEREST_RATE2);

            thisAccount.output(cout);
            thisAccount.output(outputfile);
        }
}

            Account::Account ( double Balance, double InterestRate1, double InterestRate2)

            { 
                balance = Balance;
                interest_rate1 = InterestRate1;
                interest_rate2 = InterestRate2;
                    Payment();
            }

            Account::Account()
            {
                balance = 0;
            }
double Account::InterestDue()
{ 
    return interest;
}
{
double Account::TotalAmountDue()
    }
void Account::output(ostream &out)

double Account:: Payment( )
{

double newbalance; 

if ( balance > LEVEL_ONE_BALANCE)
     interest = (balance - LEVEL_ONE_BALANCE) * interest_rate2 + LEVEL_ONE_BALANCE * interest_rate1;
else
     interest = balance * interest_rate1;

newbalance = balance + interest;

payment = newbalance* MINIMUM_PAYMENT_PERCENT;

if ( newbalance < MINIMUM_PAYMENT)
     payment = newbalance;
else
     if ( payment < MINIMUM_PAYMENT)
          payment=MINIMUM_PAYMENT;

return payment;
}
void Account::output(ostream &out)

{  out.setf(ios::fixed);      out.setf(ios::showpoint);     out.precision(2);
   out << "\n\nInterestDue : $" << setw(8) << InterestDue << endl;
   out <<  "  TotalAmountDue  : $" << setw(8) << TotalAmountDue << endl;
   out <<  "Payment   : $" << setw(8) << Payment<< endl;
}

Dani AI

Generated

Quick, prioritized checklist to get this compiling and behaving the way you expect (references: , , ).

  • Fix the syntax stops first. The class definition must end with a semicolon. Remove stray semicolons that appear immediately before function bodies (for example you have a prototype then a semicolon and then { … } — remove the extra ;). Delete the duplicate/accidental prototype void Account::output(ostream &out) that appears outside a proper definition. Pay attention to misplaced braces: double Account::TotalAmountDue() must be followed by its { ... } body, not the other way around. Non-void functions must return a value (TotalAmountDue currently does not).
  • The output lines in your output function must call the member functions, not print the function names or data-member identifiers. As said, add the parentheses when calling methods. Also ensure InterestDue() actually calculates (or returns) the interest before you use it.
  • Compile iteratively and address the first error the compiler reports; later errors often cascade from earlier syntax mistakes. Use warnings (for example: g++ -Wall -Wextra -std=c++11) to catch uninitialized variables and other pitfalls.

Small concrete fixes (apply these in-place):

out << "InterestDue : $" << setw(8) << InterestDue() << endl;
out << "TotalAmountDue : $" << setw(8) << TotalAmountDue() << endl;
out << "Payment   : $" << setw(8) << Payment() << endl;
double Account::TotalAmountDue()
{
    // make sure interest is computed first (call InterestDue() or compute here)
    return balance + interest;
}

Extra notes: compute interest in one place (either in InterestDue() or in Payment()), set total_amount_due = balance + interest so it’s available if you store it, and initialize all member variables in constructors (use initializer lists). Check that outputfile opened successfully (or open it in main), and remove platform-specific system() calls if portability matters. After those fixes the program should compile and the runtime logic will be much clearer.

Recommended Answers

All 4 Replies

Hello and welcome to Daniweb.
Usually all the friendly people here would give a prompte response.
You haven't had any yet. I'm not gonna go into your code right now, but instead take a look at your posting problem.

First of all, you want to get rid of your last error. What is the error? What part is working and which doesn't?

Secondly, where's your code tags? Wrap your code in [code] tags, to make it easily readable and to give some syntax highlighting.

Lastly, your copying of the code seemed to miss out your code formatting. Or maybe you haven't even done your formatting at all? This is important, otherwise your code is junk to read and hard to manage and maintain.

Fix those problems by editing your original post, and I'm sure you'll get your help! :)
Good luck!

bandit711,

  1. u forgot ';' after class body

    class Account
    {
    };

  2. u wrote extra ';' after function prototype which must be omitted
    void open_input (ifstream& input, char name[]);

    {
    // body
    }

and here also

void open_input (ifstream& input, char name[]);
{
// body
}
  1. u wrote a bracket '{' in wrong way

    {
    double Account::TotalAmountDue()
    }
    u may write it like
    double Account::TotalAmountDue()
    {
    }

  2. this function prototype is extra

    void Account::output(ostream &out)

should be removed

  1. this method must return a value

    double Account::TotalAmountDue()
    {
    return 4;
    }

Hope Helping, and Have a Fun :)

There were a lot more errors than 2. In your output function you are missing some pairs of parentheses.

As Excizted mentioned please learn to use code tags. Type in

[code]

//code goes here

[/code]
It makes it very difficult to see what's going on with your code when the formatting is removed.

thank farag>

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.