I am learning C++ and having difficulty getting my code to compile. I get errors while compiling using VS2010, everytime I attempt to fix the errors it seems to cause a snowball effect of compilation failures. Can someone look over the code and maybe give me some hints on how to fix it?

#ifndef MENU_BUILDER_H
#define MENU_BUILDER_H
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>

using namespace std;

//Define my class
class MenuBuilder
{
double amount;
private:
string accountNumber;
string firstName;
string middleName;
string lastName;
double withdrwal;
double deposit;
double balance;

public:
MenuBuilder();
MenuBuilder(string accountNumber, string firstName, string middleName, string lastName, 
double withdrwal, double deposit);
void checkBalance();
void withdrawal();
void deposit();
void viewAccount();
void viewStatement();
void viewBankInformation();
~MenuBuilder(void);
};
MenuBuilder::MenuBuilder(void)
{
amount=2439.45;
}


MenuBuilder::~MenuBuilder(void)
{
}

void MenuBuilder::checkBalance()
{
cout<<endl<<"Current balance is: $"<<amount;
}
void MenuBuilder::withdrawal()
{
double amt;
cout<<endl<<"How much would you like to withdraw? $ ";
cin>>amt;
amount=amount-amt;
}
void MenuBuilder::deposit()
{
double amt;
cout<<endl<<"How much would you like to deposit? $ ";
cin>>amt;
amount=amount+amt;
}
void MenuBuilder::viewAccount()
{
cout<<endl<<"Name: (Phil Sutton)";
cout<<endl<<"Account Number: XXXXXXXXXX ";
}
void MenuBuilder::viewStatement()
{
cout<<endl<<"01/01/11 - McDonalds - $6.27";
cout<<endl<<"01/15/11 - Kwik Trip - $34.93";
cout<<endl<<"02/28/11 - Target - $124.21";
}
void MenuBuilder::viewBankInformation()
{
cout<<endl<<"Devry Bank, established 2011";
cout<<endl<<"(XXX) XXX-XXXX";
cout<<endl<<"12345 1st St.";
cout<<endl<<"Someplace, NJ 12345";
}
int main()
{
char choice;
MenuBuilder atm;
cout<<endl<<"Welcome to the Devry Bank Automated Teller Machine";
do
{
cout<<endl<<endl<<"1. Check balance";
cout<<endl<<"2. Make withdrawal";
cout<<endl<<"3. Make deposit";
cout<<endl<<"4. View account information";
cout<<endl<<"5. View statement";
cout<<endl<<"6. View bank information";
cout<<endl<<"7. Exit";
cout<<endl<<"Enter your choice: ";
cin>>choice;
switch (choice)
{
case '1':
atm.checkBalance();
break;
case '2':
atm.withdrawal();
break;
case '3':
atm.deposit();
break;
case '4':
atm.viewAccount();
break;
case '5':
atm.viewStatement();
break;
case '6':
atm.viewBankInformation();
break;
case '7':
cout<<endl<<"Exit the program"<<endl;
system("pause");
return 0;
default:
cout<<endl<<"Invalid choice.";
}
}while(true);
system("pause");
return 0;

#endif;
}

Recommended Answers

All 5 Replies

Hey,

Please indent your code properly.. Ok, so the only error(s) I could find was that you have a function called "deposit" and a variable with the same name.

This code is compiling for me:

#ifndef MENU_BUILDER_H
#define MENU_BUILDER_H
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>

using namespace std;

//Define my class
class MenuBuilder
{
double amount;
private:
string accountNumber;
string firstName;
string middleName;
string lastName;
double withdrwal;
double deposit;
double balance;

public:
MenuBuilder();
MenuBuilder(string accountNumber, string firstName, string middleName, string lastName, 
double withdrwal, double deposit);
void checkBalance();
void withdrawal();
void tdeposit();
void viewAccount();
void viewStatement();
void viewBankInformation();
~MenuBuilder(void);
};
MenuBuilder::MenuBuilder(void)
{
amount=2439.45;
}


MenuBuilder::~MenuBuilder(void)
{
}

void MenuBuilder::checkBalance()
{
cout<<endl<<"Current balance is: $"<<amount;
}
void MenuBuilder::withdrawal()
{
double amt;
cout<<endl<<"How much would you like to withdraw? $ ";
cin>>amt;
amount=amount-amt;
}
void MenuBuilder::tdeposit()
{
double amt;
cout<<endl<<"How much would you like to deposit? $ ";
cin>>amt;
amount=amount+amt;
}
void MenuBuilder::viewAccount()
{
cout<<endl<<"Name: (Phil Sutton)";
cout<<endl<<"Account Number: XXXXXXXXXX ";
}
void MenuBuilder::viewStatement()
{
cout<<endl<<"01/01/11 - McDonalds - $6.27";
cout<<endl<<"01/15/11 - Kwik Trip - $34.93";
cout<<endl<<"02/28/11 - Target - $124.21";
}
void MenuBuilder::viewBankInformation()
{
cout<<endl<<"Devry Bank, established 2011";
cout<<endl<<"(XXX) XXX-XXXX";
cout<<endl<<"12345 1st St.";
cout<<endl<<"Someplace, NJ 12345";
}
int main()
{
char choice;
MenuBuilder atm;
cout<<endl<<"Welcome to the Devry Bank Automated Teller Machine";
do
{
cout<<endl<<endl<<"1. Check balance";
cout<<endl<<"2. Make withdrawal";
cout<<endl<<"3. Make deposit";
cout<<endl<<"4. View account information";
cout<<endl<<"5. View statement";
cout<<endl<<"6. View bank information";
cout<<endl<<"7. Exit";
cout<<endl<<"Enter your choice: ";
cin>>choice;
switch (choice)
{
case '1':
atm.checkBalance();
break;
case '2':
atm.withdrawal();
break;
case '3':
atm.tdeposit();
break;
case '4':
atm.viewAccount();
break;
case '5':
atm.viewStatement();
break;
case '6':
atm.viewBankInformation();
break;
case '7':
cout<<endl<<"Exit the program"<<endl;
system("pause");
return 0;
default:
cout<<endl<<"Invalid choice.";
}
}while(true);
system("pause");
return 0;

#endif;
}

-- output
Welcome to the Devry Bank Automated Teller Machine

  1. Check balance
  2. Make withdrawal
  3. Make deposit
  4. View account information
  5. View statement
  6. View bank information
  7. Exit
    Enter your choice: 1

Current balance is: $2439.45

  1. Check balance
  2. Make withdrawal
  3. Make deposit
  4. View account information
  5. View statement
  6. View bank information
  7. Exit
    Enter your choice: 2

How much would you like to withdraw? $ 100

  1. Check balance
  2. Make withdrawal
  3. Make deposit
  4. View account information
  5. View statement
  6. View bank information
  7. Exit
    Enter your choice: 1

Current balance is: $2339.45

  1. Check balance
  2. Make withdrawal
  3. Make deposit
  4. View account information
  5. View statement
  6. View bank information
  7. Exit
    Enter your choice:

Hope this helps you :)

P.S. Try avoiding inputting/outputting data within side your class functions. This is not good, especially if you wanted to use a different from of IO than cout, cin.

Try to avoid system calls in your program.

Thanks for the advice, I made some changes. Now I am stuck with a syntax error C2059 on one line.
menubuilder.cpp(77): error C2059: syntax error : '}'
I included my new code. Frankly, I am stumped on how to fix this one.

// Library
#ifndef MENU_BUILDER_H
#define MENU_BUILDER_H
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>

using namespace std;

//Define my class
class MenuBuilder
{
double amount;
private:// Private - DO NOT EDIT
string accountNumber;
string firstName;
string middleName;
string lastName;
double withdrwal;
double deposit;
double balance;

public:
MenuBuilder();
MenuBuilder(string accountNumber, string firstName, string middleName, string lastName, 
double withdrwal, double deposit);
void checkBalance();
void withdrawal();
void tdeposit();
void viewAccount();
void viewStatement();
void viewBankInformation();
~MenuBuilder(void);
};
MenuBuilder::MenuBuilder(void)
{
amount=2439.45;
}


MenuBuilder::~MenuBuilder(void)
{
}

void MenuBuilder::checkBalance()
{
cout<<endl<<"Current balance is: $"<<amount;
}

void MenuBuilder::withdrawal()
{


    double amt;
    cout<<endl<<"How much would you like to withdraw? $ ";
    cin>>amt;
    amount=amount-amt;
    do{
        if (amt<0 || amt>balance)
            {
                cout << "That is an invalid amount." << endl;
                break;

             } 
                          else 
                          {
                              amount = (amount-amt);    
                              cout << "Thank you, your new balance is $" << amount << "." << endl; 
                              break;
                          }


    }
}
void MenuBuilder::tdeposit()
{
    double amt;
        cout<<endl<<"How much would you like to deposit? $ ";
        cin>>amt;
            if(deposit > 0)
                  {
                      amount = (amount+amt);    
                      cout << "Thank you, your new balance is $" << amount << ".";
                  }
                  break;
}

void MenuBuilder::viewAccount()
    {
        cout<<endl<<"Name: (Phil Sutton)";
        cout<<endl<<"Account Number: 123456789 ";
    }
void MenuBuilder::viewStatement()
    {
        cout<<endl<<"01/01/11 - McDonalds - $6.27";
        cout<<endl<<"01/15/11 - Kwik Trip - $34.93";
        cout<<endl<<"02/28/11 - Target - $124.21";
    }
void MenuBuilder::viewBankInformation()
    {
        cout<<endl<<"Devry Bank, established 2011";
        cout<<endl<<" (123) 456-7890 ";
        cout<<endl<<"12345 1st St.";
        cout<<endl<<"Someplace, NJ 12345";
    }
int main()//Main menu
    {
        char choice;
        MenuBuilder atm;
            cout<<endl<<"Welcome to the Devry Bank Automated Teller Machine";
        do
            {
                cout<<endl<<endl<<"1. Check balance";
                cout<<endl<<"2. Make withdrawal";
                cout<<endl<<"3. Make deposit";
                cout<<endl<<"4. View account information";
                cout<<endl<<"5. View statement";
                cout<<endl<<"6. View bank information";
                cout<<endl<<"7. Exit";
                cout<<endl<<"Enter your choice: ";
                    cin>>choice;
                        switch (choice)// Case List
                            {
                                case '1':
                                atm.checkBalance();
                                break;
                                case '2':
                                atm.withdrawal();
                                break;
                                case '3':
                                atm.tdeposit();
                                break;
                                case '4':
                                atm.viewAccount();
                                break;
                                case '5':
                                atm.viewStatement();
                                break;
                                case '6':
                                atm.viewBankInformation();
                                break;
                                case '7':
                                cout<<endl<<"Exit the program"<<endl;
                                system("pause");
                                return 0;
                                default:
                                cout<<endl<<"Invalid choice.";
                        }
    }while(true);
        system("pause");
        return 0;
        #endif;
  }

Consistent formatting is the key. See this and refine your indentation. I believe this will fix your problem when you indent properly.

Sorry, my formatting kind of stinks. Figured out the issue, cleaned it up. Compiles and tests out fine. Thanks, everyone!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.