So Lost! Please Help!!

This is a discussion on So Lost! Please Help!! within the C++ Programming forums, part of the General Programming Boards category; My code is supposed to output: Enter account balance: Enter account interest rate: Enter the number of months until maturity ...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    29

    So Lost! Please Help!!

    My code is supposed to output:
    Enter account balance:
    Enter account interest rate:
    Enter the number of months until maturity
    (must be 12 or fewer months):
    When your CD matures in _ months,
    it will have a balance of $(whatever the total is)

    but it keeps telling me that EVERYTHING is not accessible in function main( )... Here is my code, please help me out, I would appreciate it A LOT!!

    Code:
    #include <iostream>
    using namespace std;
    
    class CDAccount
    {
    public:
            void input( );
            void output( );
    
            void set(int new_balance, int new_interest_rate, int new_term);
    
            int get_balance( );
    
            int get_interest_rate( );
    
            int get_term( );
    
            int get_data( );
    
    private:
            //void check_data( );
            int balance;
            int interest_rate;
            int term;
    };
    
    int main( )
    {
            CDAccount account;//, get_data;
    
            double rate_fraction, interest;
            rate_fraction = account.interest_rate/100.0;
            interest = account.balance*rate_fraction*(account.term/12.0);
            account.balance = account.balance + interest;
    
            cout.setf(ios::fixed);
            cout.setf(ios::showpoint);
            cout.precision(2);
            cout << "When your CD matures in "
                 << account.term << " months,\n"
                 << "it will have a balance of $"
                 << account.balance << endl;
            return 0;
    }
    
    void CDAccount::input( )
    {
            cout << "Enter account balance: $";
            cin >> balance;
            cout << "Enter accouunt interest rate: ";
            cin >> interest_rate;
            cout << "Enter the number of months until maturity\n"
                 << "(must be 12 or fewer months): ";
            cin >> term;
            //check_data( );
    }
    
    void CDAccount::output( )
    {
            cout << "balance =" << balance
                 << ", interest rate = " << interest_rate
                 << ", term = " << term << endl;
    }
    
    void CDAccount::set(int new_balance, int new_interest_rate, int new_term)
    {
            balance = new_balance;
            interest_rate = new_interest_rate;
            term = new_term;
            //check_data( );
    }
    
    int CDAccount::get_balance( )
    {
            return balance;
    }
    
    int CDAccount::get_interest_rate( )
    {
            return interest_rate;
    }
    int CDAccount::get_term( )
    {
            return term;
    }

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    You have the variables in CDAccount marked as private. That means you can't access them in main() directly, or anywhere else for that matter, except from inside CDAccount.

    You do, however, have public member functions of CDAccount that return the values of said private variables. Public member functions can be accessed from anywhere, which is what public means.

    If this still doesn't help you see the solution, you need to review classes and the definitions of public and private and how that affects your code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I lost my laptop, DVD and money
    By Sang-drax in forum A Brief History of Cprogramming.com
    Replies: 21
    Last Post: 10-01-2004, 07:13 PM
  2. lost disk
    By Benzakhar in forum Linux Programming
    Replies: 7
    Last Post: 01-11-2004, 05:18 PM
  3. So LOST!!!
    By Drew Vance in forum C Programming
    Replies: 6
    Last Post: 04-25-2003, 05:37 PM
  4. Lost ID number
    By ripper079 in forum C++ Programming
    Replies: 13
    Last Post: 10-04-2002, 12:51 PM
  5. API, LOST... help
    By Unregistered in forum Windows Programming
    Replies: 5
    Last Post: 03-13-2002, 02:19 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21