#endif
class BankAccount
{
public:
	double enterAccountData();
	double computeInterest();
	void displayAccount();
private:
	int accountNumber;
	double accountBalance;
	static const double RATE;
}


#include "stdafx.h"



#include <stdlib.h>

#include <conio.h>


#include <stdio.h>

#include <dos.h>

#include <ctype.h>


#include<iostream>// holds the cin and cout commands

#include<conio.h>// holds the getche() instruction
using namespace std;
//#include "BankAccount.h"

double RATE = .03;
double BankAccount::enterAccountData()
{
	double number;
	double balance;
	cout<<"Enter the account number"<<endl;
	cin>>number;
	while(number<0){
		cout<<"Account number can not be negative."<<endl<<"Enter account number."<<endl;
		cin>>number;
	}
	while(number<1000){
		cout<<"Account number can not be less than 1000."<<endl<<"Enter account number."<<endl;
		cin>>number;
		cout<<endl;
	}
	cout<<"Enter the account balance"<<endl;
	cin>>balance;
	while(balance<0){
		cout<<"Account balance can not be negative."<<endl<<"Enter account balance."<<endl;
		cin>>balance;
		cout<<endl;
	}
}

double BankAccount::computeInterest()
{
	double years;
	double balanceYear, balance1;
	cout<<number<<endl;
	balance1=balance;
	int i=1;
	while(i<=years){
		balanceYear=balance1+(balance1*RATE);
		cout<<"Year "<<i<<": the balance is "<<balanceYear<<endl;
		balance1=balanceYear;
		i++;
	}
}

void BankAccount::displayAccount()
{
	cout<<"The bank account number is "<<number<<"."<<endl;
	cout<<"The bank account balance is "<<balance<<"."<<endl;
}


int main ()
{
	BankAccount A;
    
    A.enterAccountData();    
    A.computeInterest();    
    A.displayAccount();
	return 0;
}



    //  getche();  // necessary to hold the output for the user to read
//}

It wont compile. i dont think the implementation is correct, any suggestions?

I think you need to include more headers... no only kidding. First remove that stray #endif . Then put a semicolon after your class declaration. Get rid off all of the header includes except iostream (substitute cin.getc(); for your conio function). If you are using VC++ you may need to turn off precompiled headers to get rid of stdafx.h. There are a few other smaller errors but those should be easy to find once you get rid of these.

I think you need to include more headers... no only kidding. First remove that stray #endif . Then put a semicolon after your class declaration. Get rid off all of the header includes except iostream (substitute cin.getc(); for your conio function). If you are using VC++ you may need to turn off precompiled headers to get rid of stdafx.h. There are a few other smaller errors but those should be easy to find once you get rid of these.

yea, thanks...but i still cant figure it out, can you help me some more?

What are the errors that you are getting now?

umm, i just dont know how to call the functions in the main program and if the class is declared correctly

Your function calls in main seem ok. You should still be getting some compile time errors, as some of your variables are declared within your member functions (where they cannot be seen within the other member functions) and they should be moved to the public or private section of your class definition.

Also, before I said cin.getc() what I really meant was cin.get(). Apologies. I don't use it on a regular basis anymore...

EDIT: I missed that they are supposed to be returning doubles. Yikes. Well, unless you move those variables into the declaration the whole business wouldn't even compile anyway.

Edited 7 Years Ago by jonsca: n/a

Your functions are wrong. They do not call+return variables like they should be. Therefore, your going to have 'undeclared identifiers'.

Edit: Actually, I am not this advanced in functions yet, so I may have been wrong..but that would be my guess. Sorry I could only give you a guess :/

Edited 7 Years Ago by restrictment: n/a

Your function calls in main seem ok. You should still be getting some compile time errors, as some of your variables are declared within your member functions (where they cannot be seen within the other member functions) and they should be moved to the public or private section of your class definition.

Also, before I said cin.getc() what I really meant was cin.get(). Apologies. I don't use it on a regular basis anymore...

EDIT: I missed that they are supposed to be returning doubles. Yikes. Well, unless you move those variables into the declaration the whole business wouldn't even compile anyway.

im a noob, what you mean move those variables into the declaration?

im a noob, what you mean move those variables into the declaration?

class BankAccount
{
public:
	double enterAccountData();
	double computeInterest();
	void displayAccount();
private:
	int accountNumber;
	double accountBalance;
	static const double RATE;
                   <--------- here
}

You have local variables number and balance that you declare (or attempt to use without declaring) within the functions. If you are going to use them put them up in the declaration (see above) so that they are visible to the methods of the class. Since you have an accountNumber and accountBalance why don't you use those?

Also, Restrictment is right, you either need to be returning doubles from those two functions (so having a return RATE*accountBalance; and perhaps the initial balance for the other one) and handle the changes to balance in main() or leave the functions as they are and change their return type to void . These are design decisions that you will have to make. My vote would be to change them to void unless they are required to return something.

Edited 7 Years Ago by jonsca: n/a

This article has been dead for over six months. Start a new discussion instead.