Need help with weird error

I keep getting this error with my Bank system code. Help me the error is expected class-name before '{' token
main
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
#include <fstream>
#include "User.h"
//Create an Balance that updates.
//Make an working interest rate.
//Create an online login id.
//Use Inhertiance
// UPDATING BALANCE
//Don't forget to try to make Balance a class of it's own if BankAccount don't work.
// Try using Vectors maybe.
//If get frustrated headbutt something hopefully I will wake up a Savant and understand everything.
using namespace std;
class BankAccount
{

public:
  BankAccount();
    void SetWithdrawl(double BankaccountWithDrawl);
    void SetChecking(double BankAccountChecking);
    void SetSaving(double BankAccountSaving);
    void SetBalance(double bankAccountBalance);
    double GetChecking();
    double GetSaving();
    double GetWithdrawl();
    double GetBalance();



private:
    double checking;
    double saving;
    double Withdrawl;
    int Balance;

};
BankAccount::BankAccount()
{
    checking =0;
    saving = 0;
    Withdrawl = 0;

}
void BankAccount::SetBalance(double bankAccountBalance)
{

    Balance=bankAccountBalance;
}
double BankAccount::GetBalance()
{

    return Balance;
}
void BankAccount::SetWithdrawl(double BankAccountWithdrawl)
{

    Withdrawl = BankAccountWithdrawl;

}
void BankAccount::SetChecking(double BankAccountChecking)
{
checking = BankAccountChecking;
}
void BankAccount::SetSaving(double BankAccountSaving)
    {

      saving=BankAccountSaving;

   }
 double BankAccount::GetChecking()
   {
       return checking;
   }
 double BankAccount::GetSaving()
 {
     return saving;
 }
 double BankAccount::GetWithdrawl() //WITHDRAWL
 {
   return Withdrawl;
 }



int main()
{

   int InputBalance;
   int InputChecking;
   int InputSavings;
   int InputWithdrawl;
  BankAccount gg;



    cout << "Please enter a starting Balance" << endl;
    cin >> InputBalance;
    gg.SetBalance(InputBalance);

        int itemmenu;

    cout << "WELCOME TO BANK OF BOOMBOOMBEEBEE " << endl;
    cout << "-------- (1) Make A WithDrawl--------" << endl;
   cout <<  "--------  (2) ADD OR SEE Your Savings------" << endl;
    cout << "-------- 3 See Checkings account-----" << endl;
    cout << "-------- 4 See your Balance--------"<< endl;
    cin >> itemmenu;


  switch (itemmenu){
case 1:
    cout << "How much would you like to withdrawal?" << endl;
cin >> InputWithdrawl;
gg.SetWithdrawl(InputWithdrawl);
int change = gg.GetBalance()-InputWithdrawl;
cout << "Your balance is  " << change << endl;

break;

cin.ignore();
}
}

User.h
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
#ifndef USER_H
#define USER_H
#include <string>
#include <cstring>
using namespace std;

class User : public BankAccount
{
    public:
        User();
       void SetUsernumber(int theUserNumber);
       void SetPassword(string theUserPassword);
         int getUserNumber();
        string getPassword();



    protected:
    private:
        int usernameNumber;
        string password;
};

#endif // USER_H

User.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
#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
#include "User.h"

User::User()
{
    usernameNumber = 0;
    password = "ERROR NO PASSWORD";

}

void User::SetUsernumber(int theUserNumber)
{
    usernameNumber = theUserNumber;
}
int User::getUserNumber()
{
    return usernameNumber;
}
string User::getPassword()
{
    return password;
}
void User::SetPassword(string theUserPassword)
{
    password = theUserPassword;
}
Oh yeah I forgot to say which one it is. User.h is where the error comes about.
I didn't read the code in detail, however it looks like you are defining BankAccount in the code file that contains main(). But your User class is derived from BankAccount so when the compiler tries to compile your User class it hasn't seen the BankAccount class. Try moving all of the BankAccount code to new files, BankAccount.h and BankAccount.cpp (just as you did for your User class). Then include BankAccount.h in User.h. I did not look for other errors.
alrededor is correct. Because your declaration for the BankAccount class is in main.cpp, when the compiler is compiling user.cpp, it does not know what BankAcount looks like. It need to know this since User is derived from BankAccount.

BTW, Withdrawal really doesn't belong as a member of BankAccount. A withdrawal is something the user does. It should affect either the checking or savings balance, but is not something that needs to be saved. It should just be a local variable.

How is the balance variable different from the checking and saving member variables?

Line 116: You're calling setWithdrawal, but that doesn't change the user's balance. A withdrawal should change the amount of money a user has in checking or savings.

Topic archived. No new replies allowed.