Question about classes

This is a discussion on Question about classes within the C++ Programming forums, part of the General Programming Boards category; Im just messing around with classes and im creating a checking account type deal. I have the program prompt the ...

  1. #1
    Unregistered
    Guest

    Question about classes

    Im just messing around with classes and im creating a checking account type deal.

    I have the program prompt the user for their:
    Name
    Date
    Deposit

    than it displays their information plus the balance

    i have everything inside an inline function
    and a while loop that keeps prompting the user if they have another transaction.

    My problem is whenever i call the function from main the balance is automatically set to 0.

    I dont have the program on me so i dont know if that would help more but basically inside the function i have balance intialized to 0 and after the deposit is read in i have balance = balance + deposit, but im assuming since the function goes out of scope everything is set back to 0?

    any ideas on how i can keep a running balance inside a class?

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    The best way to attack this is with a static variable member....

    Declare the variable static;

    Code:
    static int m_cx;
    And its running value will not be reset to 0 when the object goes out of scope

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Classes question...
    By Raigne in forum C++ Programming
    Replies: 24
    Last Post: 09-12-2006, 01:46 AM
  2. Replies: 2
    Last Post: 07-28-2006, 02:59 PM
  3. Simple Question about Classes
    By Loctan in forum C++ Programming
    Replies: 5
    Last Post: 06-26-2006, 02:40 AM
  4. Classes and Win32 API, and another Question
    By philvaira in forum Windows Programming
    Replies: 10
    Last Post: 04-10-2004, 07:21 PM
  5. Newbie question about the Private type in classes
    By Ryeguy457 in forum C++ Programming
    Replies: 1
    Last Post: 09-07-2002, 10:17 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21