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!