Errors with Classes
May 19, 2014 at 11:40pm UTC
Hello, so I'm a beginner programmer that's just starting to work with classes, and I'm trying to make a simple bank program that lets you add, withdraw, and add interest to a total balance amount. However when I run what I have (Down below) It generates the following errors:
error C2143: syntax error: missing ';' before 'using' File - Account.cpp on Line 2
error C2143: syntax error: missing ';' before 'using' File - main.cpp on Line 2
I'm really not sure what I'm doing wrong here and any help on how to remedy the situation would be much appreciated. Thanks!
Here's what I got so far.
Account.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#ifndef _ACCOUNT_
#define _ACCOUNT_
#include<iostream>
#include<conio.h>
using namespace std;
class Account{
public :
Account(); //Default Constructor
Account(double b, double iR); //Constructor - set balance and interest rate
void Deposit(double amount); //Adds amount to balance
void Withdraw(double amount); //subtracts amount from balance - keeps em out of the negative
void AddInterest(double iR); //Adds interest to their amount
void ChangeRate(double newRate); //Changes the Interest Rate
double CheckBalance() const ; //returns balance
double CheckInterestRate() const ; //Returns interest rate
private :
double balance;
double iR;
}
#endif
Account.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
#include"Account.h"
using namespace std;
Account::Account(){
balance = 0;
iR = .01;
}
Account::Account(double b, double iR){
balance = b;
iR = iR;
}
void Account::Deposit(double amount){
balance+=amount;
}
void Account::Withdraw(double amount){
if (balance-=amount < 0)
cout<<"Insuficient Funds - Transaction Canceled" <<endl;
else
balance-=amount;
}
void Account::AddInterest(double iR){
int n = balance*=iR;
balance+=n;
}
void Account::ChangeRate(double newRate){
iR = newRate;
}
double Account::CheckBalance() const {
return balance;
}
double Account::CheckInterestRate() const {
return iR;
}
and finally main.cpp
1 2 3 4 5 6 7 8 9 10
#include"Account.h";
using namespace std;
int main(){
Account bank(100.00, .01);
cout<<bank.CheckBalance()<<endl;
cout<<bank.CheckInterestRate()<<endl;
_getch();
return 0;
}
May 19, 2014 at 11:48pm UTC
You forgot a semicolon at the end of the class definition:
1 2 3 4
class Account
{
/* ... */
}; // <-- semicolon here
May 20, 2014 at 3:04pm UTC
Ahhh thanks
Topic archived. No new replies allowed.