May 1, 2014 at 11:07pm UTC
This should be pretty simple, but I cant figure it out. I will give you all three of my files and the error code I am getting, if someone could help.
.h file
using namespace std;
class Account
{
public:
Account();
Account (double);
double getBalance();
void deposit(double);
void withdraw(double);
void addInterest(double);
private:
double balance;
};
Account.ccp file
#include<iostream>
using namespace std;
#include "Account_A.h"
Account::Account()
{
balance=0.0;
};
Account::Account(double intialBalance)
{
balance=intialBalance;
};
void Account::deposit(double depositAmount)
{
balance=balance+depositAmount;
};
void Account::withdraw(double withdrawAmount)
{
balance=balance-withdrawAmount;
};
double Account::getBalance()
{
return balance;
};
void Account::addInterest(double rate)
{
double balance=balance+balance*rate;
};
useAccount.ccp file
#include<iostream>
using namespace std;
#include "Account_A.h"
int main()
{
Account a1;
Account a2(500);
a1.deposit(200);
a2.withdraw(50);
a1.addInterest(0.2);
cout<<a1.getBalance();
cout<<"\n";
cout<<a2.getBalance();
system("pause");
return 0;
}
Error Code
1>------ Build started: Project: Lab_7_A, Configuration: Debug Win32 ------
1> useAcconut.cpp
1> Account.cpp
1> Generating Code...
1>c:\users\nate\documents\visual studio 2012\projects\lab_7_a\account.cpp(32): error C4700: uninitialized local variable 'balance' used
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========