05-16-2009, 02:06 AM | #1 |
I'm new at this, please be kind...
How do I reference the name of an image's "title"?
For example: Account account1 = new Account(50.00M); Account account2 = new Account(-7.53M); Later in my coding, I print a line that has the name of the account hard coded, and the value, at that point in the process, referenced with one of these: {0}. I forget the name of it. Index something or other? What I want to do is the not have the account's name thingie hard coded. I'm guessing that I'd have to use some sort of loop, where with each time through, only one account would dealt with. So, instead of ("account1 balance is {0}.", Balance) I could have ("{0} balance is {1}.", [way of referencing object's title], Balance); I'm sorry if I couldn't explain this well enough. |
|
05-16-2009, 04:57 AM | #2 |
Re: I'm new at this, please be kind...
Im confused on what your trying to do.
This shouldn't even compile cause of the "m" after the 50.00. Account account1 = new Account(50.00M); Account account2 = new Account(-7.53M); im assuming 50.00 represents money. so im assuming you want something like this? Code:
class idAccount { public: idAccount( string name, int amount ); void print_data( void ); void GiveMoney( int moneyAmmount ) protected: string name; int amount; } idAccount::idAccount( string name, int amount ) { this->name = name; this->amount = amount; } void idAccount::print_data( void ) { printf("Account %s has $%d\n", name.c_str(), amount ); } void idAccount::GiveMoney( int moneyAmmount ) { amount += moneyAmmount; } void main( void ) { idAccount acct1 = new idAccount( "iceColdDuke", 500 ); acct1->print_data(); acct1->GiveMoney( 50 ); acct1->print_data(); }
Last edited by IceColdDuke; 05-16-2009 at 05:03 AM.
|
|
05-16-2009, 06:37 PM | #3 |
Re: I'm new at this, please be kind...
If you checked the other thread, the book I recommended would be a great starting point. But our always helpfull IceColdDuke gave you an good example
__________________
Duke Nukem Forever Who am I to judge? |
|
Bookmarks |
|
|