class problem?

hi friends, i have a problem regarding class my problem is here below
(Account Class) Create a class called Account that a bank might use to represent customers' bank accounts. Your class should include one data member of type int to represent the account balance. Your class should provide a constructor that receives an initial balance and uses it to initialize the data member. The constructor should validate the initial balance to ensure that it is greater than or equal to 0. If not, the balance should be set to 0 and the constructor should display an error message, indicating that the initial balance was invalid. The class should provide three member functions. Member function credit should add an amount to the current balance. Member function debit should withdraw money from the Account and should ensure that the debit amount does not exceed the Account's balance. If it does, the balance should be left unchanged and the function should print a message indicating "Debit amount exceeded account balance." Member function getBalance should return the current balance. Create a program that creates two Account objects and tests the member functions of class Account.

and i make my code but here is problem with it not compile the code is here below
#include<iostream.h>
class account{
private:
int balance;// data member that store the balance
public:
account(int);// initilize constructor
void credit(int);// initilize credit to add amount to balance
void debit(int);// initilize to withdraw from balance
int getbalance();//return balance
int getdebit();//return debit balance
int getcredit();//return credit balance
};//end of class
account::account(int initialbalance)// default constructor
balance=0; //initilize balance
if(initialbalance>=0)
balance=initialbalance;
if(initialbalance<0)
cout<<"ERROR: you type an invalid balance"<<endl;
}
account::credit(int amountd);//this is credit function which add the deposit amount
{
credit=balance+amountd;
}
account::debit(int amountw)
{
if(amountw>initialbalance)
cout<<"debit amount acceed account balance";
if(amountw<inititalbalance)
debit=balance-amountw;
}
account::getbalance()
{
return balance;
}
account::getdebit();
{
return debit;
}
account::getcredit();
{
return credit;
}
main()
{
int amountw,int amountd;
cout<<"enter amount withdraw"<<endl;
cin>>amountw;
cout<<"enter amount deposit"<<endl;
cin>>amountd;
account no1;
no1.getbalance();
no1.getdebit();
no1.credit();
}


i need help anyone who can point out my mistake and correct it
i shall be very thankful to all of you. waiting for reply
regard,
sehrish
You forgot using namespace std; underneath #include <iostream>

Use <iostream> and NOT <iostream.h>
no the problem is not here my compiler work on only iostream.h the errors are here
14: error: expected init-declarator before "balance"
14: error: expected `,' or `;' before "balance"
:15: error: expected unqualified-id before "if"
:15: error: expected `,' or `;' before "if"
:17: error: expected unqualified-id before "if"
: error: expected `,' or `;' before "if"
:19: error: expected declaration before '}' token

first i cannot understand about unqulified id if u can help in this regard, plz do it

your not in the same class anymore, so you should redeclare balance as an int (scope problem)
also, you should make this part a function, or a class, since it's now none of them :) (i think, but i'm learning on classes right now, so i'm not sure)

Hope it helps,

Cheers!
i think i forget putting brace at default constructor i correct it now
account::account(int initialbalance){// default constructor
balance=0; //initilize balance
if(initialbalance>=0)
balance=initialbalance;
if(initialbalance<0)
cout<<"ERROR: you type an invalid balance"<<endl;
}
}
but now one error is still there compiler require declaration before last brace but i remove it then 25 error occurs if any one can understand any solid problem in code then plz tell
thanks in advance
regards,
Topic archived. No new replies allowed.