Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,266 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,493 people online right now. Registration is fast and FREE... Join Now!




help fix Compiling error

 
Reply to this topicStart new topic

help fix Compiling error, bank account program need to fix error

rantwi
1 Dec, 2006 - 08:53 PM
Post #1

New D.I.C Head
*

Joined: 1 Dec, 2006
Posts: 4


My Contributions
I am working on program and I need to fix some small errors, you don't need to fix the program because it is not done yet, but if you can help me fix the compiling error, especially the first error that will help.

main //not much is done ,just check for file open and close
CODE

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;

#include "account.h"
#include "savings.h"

int Account::NDM =0;
int Account::NW =0;
int main()
{
    ifstream infile;
    char filename[14];
    
    cout <<"Enter the filename: ";
    cin >>filename;

    fileOpen(filename, infile);
    fileClose(infile);

return 0;
}
    void fileOpen(char filename[14], ifstream& infile)
    {
        infile.open(filename);
    if (infile.fail())
    {
        cerr << "\a\nERROR 1: File could not be opened."<<endl;
        exit(1);
    }
    else
    {
        cout << "\nThe external file has been successfully opened for writing."<<endl;
    }
        return;
    }    

    void fileClose(ifstream& infile)
    {
        infile.close();
    if (infile.fail())
        {
        cerr << "\a\nERROR 2: File could not be closed."<< endl;
        exit(2);
        }
    else
        {
        cout <<"\nThe external file has been successfully closed."<<endl;
        }
        return;
    }


Account.h
CODE

class Account
{

    protected:
static  int NDM,NW;
        double MIR,MI,bal,MonScharge;
        float Ai,money;
    public:
        Account(int);
        void deposit(int);
        void withdraw(int);
        void calclnt();
        void MonthlyProc();
};

Account::Account(int mon):bal(0.0),Ai(0.0)
{
    money = mon;
    NDM++;
    NW++;
}

void Account::deposit(int mon)
{
    money = mon;
    bal = bal+money;
    return;
}

void Account::withdraw(int mon)
{
    money = mon;
    bal = bal-money;
    return;
}
void Account::calclnt()
{
    MIR = Ai/12;
    MI = bal*MIR;
    bal = bal+MI;
    return;
}

void Account::MonthlyProc()
{
    bal = bal-MonScharge;
    calclnt();
    NW=0;
    NDM=0;
    MonScharge=0;
    return;
}


Savings.h
CODE

class Savings:protected Account
{
public:
void    withdraw();
void    deposit(int);
void    MonthlyProc();
};

void Savings::withdraw()
{
    {
    if (bal >= 25)
        Account::withdraw(int)
        NW++;
    }

        else
    {
        cerr <<"\nSorry balance is below $25 *Can't withdraw*"<<endl;
    }
    return;
}

void Savings::deposit(int)
{
    money = mon;
    if(bal+money >= 25.0)
    {
        Account::deposit(int);
        NDM++;
    }
    else
    {
        cout <<"\nSorry the money your depositing will not make the account active."<<endl;
    }
    return;
}

void Savings::MonthlyProc()
{
    if(NW >4)
    {
    MonScharge=1;
    Account::MonthlyProc();
    }
    else
    {
        Account::MonthlyProc();
    }
    if(bal =>25)
    {
        cout <<"\nAccount is Active."<<endl;
    }
    else
    {
        cout <<"\nAccount is Inactive."<<endl;
    }
    return;
}

User is offlineProfile CardPM
+Quote Post

Jayman
RE: Help Fix Compiling Error
1 Dec, 2006 - 09:26 PM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,985



Thanked: 44 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
Post the error messages that you are getting.
User is offlineProfile CardPM
+Quote Post

horace
RE: Help Fix Compiling Error
2 Dec, 2006 - 12:15 AM
Post #3

D.I.C Addict
Group Icon

Joined: 25 Oct, 2006
Posts: 573



Thanked: 4 times
Dream Kudos: 50
My Contributions
fixed a few errors in Accounts.h - in particular you need a default constructor if you have a constructor with parameters and there were two versions of void Account::deposit(int mon)
CODE

class Account
{

    protected:
static  int NDM,NW;
        double MIR,MI,bal,MonScharge;
        float Ai,money;
    public:
        Account();  // ** added
        Account(int);
        void deposit(int);
        void withdraw(int);
        void calclnt();
        void MonthlyProc();
};

Account::Account():bal(0.0),Ai(0.0)   // ** you need a default constructor
{
    money = 0;  
    NDM++;
    NW++;
}

void Account::deposit(int mon)
{
    money = mon;
    bal = bal+money;
    return;
}

/*void Account::deposit(int mon)    // ** second version of Account
{
    money = mon;
    bal = bal+money;
    return;
}*/

void Account::withdraw(int mon)
{
    money = mon;
    bal = bal-money;
    return;
}
void Account::calclnt()
{
    MIR = Ai/12;
    MI = bal*MIR;
    bal = bal+MI;
    return;
}

void Account::MonthlyProc()
{
    bal = bal-MonScharge;
    calclnt();
    NW=0;
    NDM=0;
    MonScharge=0;
    return;
}


now have a go at fixing other errors, e.g. in Saving::withdraw() what should be the parameter to
CODE

        Account::withdraw(int)


This post has been edited by horace: 2 Dec, 2006 - 04:00 AM
User is offlineProfile CardPM
+Quote Post

rantwi
RE: Help Fix Compiling Error
2 Dec, 2006 - 04:36 AM
Post #4

New D.I.C Head
*

Joined: 1 Dec, 2006
Posts: 4


My Contributions
I have managed to fix some, but the first one from before will not "bug" away.

CODE
--------------------Configuration: base account - Win32 Debug--------------------
Compiling...
main.cpp
c:\documents and settings\administrator\desktop\final project\base account\savings.h(14) : error C2144: syntax error : missing ')' before type 'int'
c:\documents and settings\administrator\desktop\final project\base account\savings.h(14) : error C2660: 'withdraw' : function does not take 0 parameters
c:\documents and settings\administrator\desktop\final project\base account\savings.h(14) : error C2059: syntax error : ')'
c:\documents and settings\administrator\desktop\final project\base account\savings.h(30) : error C2144: syntax error : missing ')' before type 'int'
c:\documents and settings\administrator\desktop\final project\base account\savings.h(30) : error C2660: 'deposit' : function does not take 0 parameters
c:\documents and settings\administrator\desktop\final project\base account\savings.h(30) : error C2059: syntax error : ')'
Error executing cl.exe.

base account.exe - 6 error(s), 0 warning(s)


User is offlineProfile CardPM
+Quote Post

horace
RE: Help Fix Compiling Error
2 Dec, 2006 - 05:06 AM
Post #5

D.I.C Addict
Group Icon

Joined: 25 Oct, 2006
Posts: 573



Thanked: 4 times
Dream Kudos: 50
My Contributions
QUOTE(rantwi @ 2 Dec, 2006 - 12:36 PM) *

I have managed to fix some, but the first one from before will not "bug" away.

CODE
--------------------Configuration: base account - Win32 Debug--------------------
Compiling...
main.cpp
c:\documents and settings\administrator\desktop\final project\base account\savings.h(14) : error C2144: syntax error : missing ')' before type 'int'
c:\documents and settings\administrator\desktop\final project\base account\savings.h(14) : error C2660: 'withdraw' : function does not take 0 parameters
c:\documents and settings\administrator\desktop\final project\base account\savings.h(14) : error C2059: syntax error : ')'
c:\documents and settings\administrator\desktop\final project\base account\savings.h(30) : error C2144: syntax error : missing ')' before type 'int'
c:\documents and settings\administrator\desktop\final project\base account\savings.h(30) : error C2660: 'deposit' : function does not take 0 parameters
c:\documents and settings\administrator\desktop\final project\base account\savings.h(30) : error C2059: syntax error : ')'
Error executing cl.exe.

base account.exe - 6 error(s), 0 warning(s)


the probelems are in lines 13 and 29, i.e.
CODE

        Account::withdraw(int)

line 13 has a ; missing off the end and both have the parameter int which is a C++ keyword using to declare integer variables.

have a look at
http://www.cplusplus.com/doc/tutorial/functions.html
on how function parameters are declared and passed
User is offlineProfile CardPM
+Quote Post

rantwi
RE: Help Fix Compiling Error
2 Dec, 2006 - 05:42 AM
Post #6

New D.I.C Head
*

Joined: 1 Dec, 2006
Posts: 4


My Contributions
WOW! zero errors, and all I had to do is insted of Account::withdraw(int); it would be:

CODE

void Account::withdraw(int);



Thanx horace smile.gif
User is offlineProfile CardPM
+Quote Post

rantwi
RE: Help Fix Compiling Error
2 Dec, 2006 - 06:14 AM
Post #7

New D.I.C Head
*

Joined: 1 Dec, 2006
Posts: 4


My Contributions
I have another question if you don't mind
I want to open a file like this:

Account Type Traction Type Amount

S w 1000
S 0 234
S d 34
c e 200
S e 2000



I want to be able to link s=savings, then w=withdraw, and then either deposit or withdraw(depending on the traction type, o-open and d=deposit)

of course I have started the program as you can see from above, but I am not looking the answer, but if you can direct me to a link that I can learn this that will be helpful

PS, I know how to assign data types to work for specific type (like string for s,w,o and int or double for 1000,234..)

User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Help Fix Compiling Error
2 Dec, 2006 - 06:27 AM
Post #8

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
File I/O

http://www.cplusplus.com/doc/tutorial/files.html

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/4/08 07:30PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month