Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 131,723 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,314 people online right now. Registration is fast and FREE... Join Now!




Checkbook Class

 
Reply to this topicStart new topic

Checkbook Class

hash_code21
post 21 Nov, 2005 - 08:30 AM
Post #1


New D.I.C Head

*
Joined: 12 Oct, 2005
Posts: 22


My Contributions


I am writing a checkbook class that contains three member functions: deposit(), withdrawl(), and balance(). The program asks the user to continually enter an amount in the form of -xx.xx for withdrawl and xx.xx for deposit. After each entry, the program either utilizes the deposit or withdrawl function and then uses the balance function to display the new checkbook value. All of my values are of type double and everything works fine, except that the value returned by balance() looks like: -9.25596e+061.

Here is the code I used:

CODE

#include <iostream>
using namespace std;

class checkbook {
private:
    double d_amount;    // deposit amount
    double w_amount;    // withdrawl amount
    double total;  // balance total
public:
    void init();      // initialize all values
    void deposit(double input);      // add to the checkbook
    void withdrawl(double input);  // subtract from the checkbook
    double balance();  // sum of values in checkbook
};

inline void checkbook::init()
{
    d_amount = 00.00;
    w_amount = 00.00;
    total = 00.00;
}

inline void checkbook::deposit(double input)
{
    total = total+input;
}

inline void checkbook::withdrawl(double input)
{
    total = total-input;
}

inline double checkbook::balance()
{
    return(total);
}

void main()
{
    checkbook my_checkbook;
    double entry;

    cout << "Welcome to your checkbook\n\n";
    cout << "Enter a value in the form -xx.xx (withdrawl) or xx.xx (deposit)\n\n";
    
    while(true) {
       cout << "Enter a value: ";
 cin >> entry;

 if (entry < 0) {
     my_checkbook.withdrawl(entry);
     cout << "BALANCE: " << my_checkbook.balance();
 } else {
     my_checkbook.deposit(entry);
     cout << "BALANCE: " << my_checkbook.balance();
 }
    }
}


Any help is appreciated while I continue. Thanks!
User is offlineProfile CardPM

Go to the top of the page

hash_code21
post 21 Nov, 2005 - 01:28 PM
Post #2


New D.I.C Head

*
Joined: 12 Oct, 2005
Posts: 22


My Contributions


Nevermind! I just realized that I never called my init() function when I created a new instance of the class. It works now!
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/20/08 10:10AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month