Thread: program wont compile..why?

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    31

    program wont compile..why?

    i did a code similar to one posted on here not too long ago. i only get 2 errors but i cant figure out how to fix them.
    heres the code--
    Code:
    #include <iostream>
    #include <cstdlib>
    using namespace std;
    
    class account
    {
     public:
     int deposit(int deposit);
     int withdrawal(int withdrawal);
     void getbalance(void);
     private:
     int balance;
    };
    
    int account::deposit(int deposit)
    {
     cout<<"How much would you like to deposit?"<<endl;
     cin>>deposit;
     int balance = balance + deposit;
     cout<<"Thank you. Your balance is now "<<balance;
     return balance;
    }
    
    int account::withdrawal(int withdrawal)
    {
     cout<<"How much would you like to withdraw?"<<endl;
     cin>>withdrawal;
     int balance = balance - withdrawal;
     cout<<"Thank you. Your balance is now "<<balance<<
     return balance;
    }
    
    void getbalance(void)
    {
     cout<<"Your balance is currently "<<balance;
    } 
    
    int main()
    {
     cout<<"What would you like to do with your account?"<<endl;
     cout<<"1. deposit"<<endl;
     cout<<"2. withdraw"<<endl;
     cout<<"3. view balance"<<endl;
     cout<<"4. cancel"<<endl;
     int Iaccount;
     cin>>Iaccount;
    
     if(Iaccount == 1)
      deposit(int deposit)
     if(Iaccount == 2)
      withdrawal(int withdrawal)
     if(Iaccount == 3)
      getbalance(void)
     if(Iaccount == 4)
     {
      cout<<"Please come again."<<endl;
     }
     system("PAUSE");
     return 0;
    }
    i may have made a couple typos in here but its all correct in the code. the only 2 errors i get are a parse error before ')' on line 48
    Code:
    deposit(int deposit)
    it looks the same as all the other if statements to me...
    and the other error is--"confused by earlier errors, bailing out" on line 56(the closing } after the 4th if statement).
    can anyone tell me why these are happening and how to fix it?

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    if(Iaccount == 1)
      deposit(int deposit)
     if(Iaccount == 2)
      withdrawal(int withdrawal)
    1 - Don't include the variable type when calling a function.
    2 - You don't have a ; on the end to terminate the statement.
    3 - You have the problem on both the second and fourth lines above.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    31
    eh...that didnt work lol. it just made more parse errors and made deposit undeclared.

  4. #4
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Because it isn't declared from what I see. What is very strange about your code is that you go ahead and call functions without any data. You don't even ask or store how much money the user wants to withdraw or deposit or anything.
    And getbalance is called like this
    Code:
    getbalance();

  5. #5
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Code:
    if(Iaccount == 1)
      deposit(int deposit)
    Looks like you want to call the method deposit() of class account.
    You need an object to do that. Same with getbalance() and withdrawal().
    Kurt

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Well posting your latest attempt would help.

    > int balance = balance - withdrawal;
    You now have a local variable and a class member variable with the same name

    > deposit(int deposit)
    1. You need an instance of the class to work with
    2. Since you ask for the amount inside the function, there isn't any point in having a parameter.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 01:42 AM
  2. Compile Public Domain Pocket PC C Program
    By m1l in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 07-20-2007, 04:02 AM
  3. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  4. new to C--can't get program to compile
    By samerune in forum C Programming
    Replies: 12
    Last Post: 04-02-2007, 09:44 AM
  5. how do i compile a program that deals w/classes?
    By Shy_girl_311 in forum C++ Programming
    Replies: 5
    Last Post: 11-11-2001, 02:32 AM