Thread: PLEASE HELP!! error C2228

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    17

    Exclamation PLEASE HELP!! error C2228

    hi, i just made an account to ask this question. i need help FAST. this is due at midnight

    testbankaccount.cpp(38) : error C2228: left of '.getBalance' must have class/struct/union

    Code:
    // #pragma once#include <iostream>
    using namespace std;
    
    
    #ifndef BANKACCOUNT_H
    #define BANKACCOUNT_H
    
    
    class BankAccount
    {
       private:
          double balance; // holds the current account balance
    	  double interestRate; // holds the interest rate for the current period
    	  double interest; // holds the interest earned for the current period
    	  int numTransactions; // holds the current number of transactions
       public:
          BankAccount();
          void setInterestRate(double);
    	  void makeDeposit(double); 
    	  bool makeWithdraw(double); 
    	  void computeInterest();
    	  double getInterestRate();
    	  double getBalance();
    	  double getInterest();
    	  int getNumTransactions();
    };
    #endif
    Code:
    #include <iostream>#include "BankAccount.h"
    using namespace std;
    
    
    #ifndef BANKACCOUNT_H
    #define BANKACCOUNT_H
    
    
    BankAccount::BankAccount()
    {
       balance = 0;
       interestRate = 0.056;
       interest = 0;
       numTransactions = 0;
    }
    void BankAccount::setInterestRate(double interestRate)
    {
    	this->interestRate = interestRate;
    }
    void BankAccount::makeDeposit(double deposit)
    {
       balance += deposit;
       numTransactions++;
    }
    bool BankAccount::makeWithdraw(double withdraw)
    {
       if (balance < withdraw)
          return false;
       else
          {
             balance -= withdraw;
             numTransactions++;
             return true;
          }
    }
    void BankAccount::computeInterest()
    {
       interest = interestRate(balance);
       balance += interest;
    }
    double BankAccount::getInterestRate()
    {
       return interestRate;
    }
    double BankAccount::getBalance()
    {
       return balance;
    }
    double BankAccount::getInterest()
    {
       return interest;
    }
    int BankAccount::getNumTransactions()
    {
       return numTransactions;
    }
    
    
    int main()
    {
    return 0;
    }
    #endif
    Code:
    #include <iostream>#include "BankAccount.h"
    using namespace std;
    
    
    void heading();
    void displayMenu();  
    void makeDeposit(BankAccount &depositAmount);  
    void makeWithdraw(BankAccount &withdrawAmount);
    
    
    int main()
    {
       heading();
       cout << endl;
       displayMenu();
    
    
       BankAccount savings;
    
    
       int userChoice;
       cin >> userChoice;        
       for (userChoice; userChoice > 6;)
          {
    	     cout << endl;
    		 cout << "There is no option " << userChoice << ". Please choose a task that is listed." << endl;
    		 cout << endl;
    		 displayMenu();
             cin >> userChoice;
           }
        if (userChoice == 6)
          {
    	   cout << endl;
           cout << "Thank you. Please wait." << endl;
    	   cout << endl;
    	   cout << "Thank you for being a loyal customer!" << endl;
    	   cout << endl;
          }
       /*if (userChoice == 1)
          {
    		 BankAccount::makeDeposit(savings);
          }
       if (userChoice == 2)
          {
             BankAccount::makeWithdraw(savings);
          }
       if (userChoice == 3)
          {
             savings.getBalance();
          }
       if (userChoice == 4)
          {
             savings.getNumTransactions();
          }
       if (userChoice == 5)
          {
             savings.getInterest();
          }*/
    }
    void heading()
    {
        cout << "/********************************************************************************************" << endl;
     	cout << "*         Course Name: CMPS 191 – Modular Programming and Algorithms Development II" << endl;
    	cout << "*                                           Project 2" << endl;
    	cout << "* Section: 01" << endl;
    	cout << "* Semester: Spring 2013" << endl;
    	cout << "*" << endl;
    	cout << "* Project Members:" << endl;  
    	cout << "*        Leader: William R. Veal III" << endl;
    	cout << "*" << endl;  
        cout << "*" << endl;
     	cout << "* Instructor: Dr. Mathieu Kourouma" << endl;
    	cout << "*" << endl;
     	cout << "* Description:" << endl;
        cout << "*	Provide here a brief description of the purpose of the project" << endl;
    	cout << "*" << endl;
    	cout << "* Due Date: Wednesday, March 26, 2013 by 11:59 PM on Blackboard" << endl;
    	cout << "*" << endl;
     	cout << "* Certificate of Authentication:" << endl;
    	cout << "*" << endl;
    	cout << "* We, the listed group members:" << endl;
    	cout << "*	 Claim that this project’s work fully our own work." << endl;
    	cout << "*	 We wrote this program independently." << endl; 
       	cout << "*	 We did not copy any part of the code from other group members." << endl;
       	cout << "*	 We did not share at all our codes with other group members." << endl;
    	cout << "* 	 We are only allowed to seek help from the instructor of this course and group members" << endl;
       	cout << "*" << endl; 
       	cout << "* Signature: WRVIII" << endl;
    	cout << "*" << endl;
     	cout << "**********************************************************************************************/" << endl;
    }
    void displayMenu()
    {
       cout << "----------------------------------------------------------------------------------------------------------------------------------" << endl;
       cout << "					                   Welcome to SUBR's Credit Union Banking System" << endl;
       cout << "-----------------------------------------------------------------------------------------------------------------------------------" << endl;
       cout << "" << endl;
       cout << "Please select from the following menu:" << endl;
       cout << " " << endl;
       cout << "1.	Make a deposit" << endl;
       cout << "2.	Make a withdraw" << endl;
       cout << "3.	Display account balance" << endl;
       cout << "4.	Display the number of transactions" << endl;
       cout << "5.	Display interest earned " << endl;
       cout << "6.	Exit the banking system" << endl;
       cout << " " << endl;
       cout << "Make your selection: ";
    }
    void makeDeposit(BankAccount &depositAmount)
    {
      double deposit;
    
    
      cout << "Enter the amount you wish to deposit: ";
      cin >> deposit;
      cout << endl;
      depositAmount.makeDeposit(deposit);
      cout << "Your deposit is " << deposit << endl;
    }
    void makeWithdraw(BankAccount &withdrawAmount)
    {
       double withdraw;
     
       cout << "Enter the amount you wish to withdraw: ";
       cin >> withdraw;
       if (!withdrawAmount.makeWithdraw(withdraw))
          cout << "The amount you want to withraw is larger than the balance." << endl;
    }

  2. #2
    Registered User
    Join Date
    Mar 2013
    Posts
    17
    i know some may find this annoying, but i need help fast. So, i will be bumping like i have walking issues

  3. #3
    Registered User
    Join Date
    Mar 2013
    Posts
    17
    i'm a beginner at c++ btw. so please be gentle

    am fragile tbh

    no homo

  4. #4
    Registered User
    Join Date
    Mar 2013
    Posts
    17
    push

  5. #5
    Registered User
    Join Date
    Mar 2013
    Location
    Portugal, Porto.
    Posts
    105
    You're a begginer but you use classes? o:

  6. #6
    Registered User
    Join Date
    Mar 2013
    Posts
    17
    Quote Originally Posted by Khabz View Post
    You're a begginer but you use classes? o:
    i'm majoring in comp. science so i'm taking programming. classes are pretty straight forward, but i am stomped on this. can you help me ?

  7. #7
    Registered User
    Join Date
    Mar 2013
    Location
    Portugal, Porto.
    Posts
    105
    I can't help you since I haven't touched on classes yet..

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,377
    Quote Originally Posted by 5.5.7. Will
    i need help FAST. this is due at midnight
    Ah, that's another 13+ hours or so. Shouldn't be a problem

    Quote Originally Posted by 5.5.7. Will
    testbankaccount.cpp(38) : error C2228: left of '.getBalance' must have class/struct/union
    The only place where I see getBalance being called is commented out. Did you actually comment it out, or...?

    Although it can be guessed, it would be better if you told us exactly which code snippet was for which file.

    Oh, and remove that using directive from your header file: you don't need it and shouldn't be having a using directive at file scope anyway. Then, remove those header inclusion guards from the source file.

    Quote Originally Posted by 5.5.7. Will
    i know some may find this annoying, but i need help fast. So, i will be bumping like i have walking issues
    Annoying the people who might want to help you is a quick way to get help slowly, if ever.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Registered User
    Join Date
    Mar 2013
    Posts
    17
    Quote Originally Posted by Khabz View Post
    I can't help you since I haven't touched on classes yet..
    dammit PLEASE HELP!! error C2228-7zo3b-jpg

  10. #10
    Registered User
    Join Date
    Mar 2013
    Posts
    17
    Quote Originally Posted by laserlight View Post
    The only place where I see getBalance being called is commented out. Did you actually comment it out, or...?
    ya, i commented it out to see if the error would go away, but it didn't

    the first file is declaration(.h), second is implementation, third is test. the error is in the test file; the last code

  11. #11
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,377
    Right. Fix the problems I outlined then try again. What do you get?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  12. #12
    Registered User
    Join Date
    Mar 2013
    Posts
    17
    Quote Originally Posted by laserlight View Post
    Right. Fix the problems I outlined then try again. What do you get?
    i'm getting the same error for some reason. the only error there

    PLEASE HELP!! error C2228-pnn30qv-jpg

  13. #13
    Registered User
    Join Date
    May 2009
    Posts
    4,092
    Quote Originally Posted by laserlight View Post
    Oh, and remove that using directive from your header file: you don't need it and shouldn't be having a using directive at file scope anyway. Then, remove those header inclusion guards from the source file.
    #include <iostream>#include "BankAccount.h"
    using namespace std;


    #ifndef BANKACCOUNT_H
    #define BANKACCOUNT_H
    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  14. #14
    -bleh-
    Join Date
    Aug 2010
    Location
    somewhere in this universe
    Posts
    463
    Code:
    void BankAccount::computeInterest()
    {
       interest = interestRate(balance);<---- interstRate is not a function, it's a variable. 
       balance += interest;
    }
    "All that we see or seem
    Is but a dream within a dream." - Poe

  15. #15
    Registered User
    Join Date
    Mar 2013
    Posts
    17
    Quote Originally Posted by stahta01 View Post
    Tim S.
    i removed them and the error still shows. this is really confusing

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 10-29-2012, 03:33 AM
  2. Error C2109 + C2228
    By deeisenberg in forum C Programming
    Replies: 8
    Last Post: 04-23-2012, 11:04 AM
  3. Replies: 4
    Last Post: 07-24-2011, 09:38 PM
  4. Replies: 3
    Last Post: 10-02-2007, 09:12 PM
  5. Compiler error c2228
    By <showMe> in forum C++ Programming
    Replies: 2
    Last Post: 06-28-2006, 08:31 PM