Questions about programming languages and debugging
maboroshi
Dr. Mab
Posts: 1624 Joined: 28 Aug 2005, 16:00
18
Post
by maboroshi » 31 Mar 2008, 16:18
is there a way to check if a value has been assigned to a variable in C++ like php's isset() function
if so is this the correct way
Code: Select all
if (total1 != 0) {
total1 += total1;
}
what I am doing is creating a continuous loop on each iteration it asks add or multiply if I replace the value that was added (total1), thats it its replaced I need a way to keep a reference to total1 in memory so I can than continue adding values to it over and over
Any ideas
Cheers
Maboroshi
Nerdz
The Architect
Posts: 1127 Joined: 15 Jun 2005, 16:00
18
Location: #db_error in: select usr.location from sucko_member where usr.id=63;
Contact:
Post
by Nerdz » 31 Mar 2008, 21:19
Hmm usually with create variable with default value like -1 or 0... and checked that it's our default value...
Number: -1 or 0
String/char*: "" or specific for string: isempty()
pointer: 0
Give a man a fish, you feed him for one day.
Learn a man to fish, you feed him for life.
ayu
Staff
Posts: 8109 Joined: 27 Aug 2005, 16:00
18
Contact:
Post
by ayu » 31 Mar 2008, 22:22
Wouldn't total1 != NULL work ? i mean "0" is a value after all.
"The best place to hide a tree, is in a forest"
Nerdz
The Architect
Posts: 1127 Joined: 15 Jun 2005, 16:00
18
Location: #db_error in: select usr.location from sucko_member where usr.id=63;
Contact:
Post
by Nerdz » 01 Apr 2008, 06:28
nha, usually there is #define NULL 0 ...
Type* p = 0;
The address of p is 0 ans it's value is not set.
Give a man a fish, you feed him for one day.
Learn a man to fish, you feed him for life.
maboroshi
Dr. Mab
Posts: 1624 Joined: 28 Aug 2005, 16:00
18
Post
by maboroshi » 01 Apr 2008, 08:11
Ok here is my base code I want to keep a reference to total1 in memory on each successive loop but can't figure out how
Please explain if you help what you did
edit guess I should use suck-o code poster
http://code.suck-o.com/7
Nerdz
The Architect
Posts: 1127 Joined: 15 Jun 2005, 16:00
18
Location: #db_error in: select usr.location from sucko_member where usr.id=63;
Contact:
Post
by Nerdz » 01 Apr 2008, 08:27
So each time total get a new value you want to keep the previous one? Why not using an array?
EDITED:
I guess I don't really understand your problem... if it's a calculator you want to do you can do:
total1 += num1 + num2;
EDITED2:
Hmm I edited the code... but I don't think that what you have in mind... is it?
http://code.suck-o.com/8
Give a man a fish, you feed him for one day.
Learn a man to fish, you feed him for life.
maboroshi
Dr. Mab
Posts: 1624 Joined: 28 Aug 2005, 16:00
18
Post
by maboroshi » 01 Apr 2008, 08:55
Alright Nerdz You win the prize
You solved my problem god that was so simple to ty buddy
Nerdz
The Architect
Posts: 1127 Joined: 15 Jun 2005, 16:00
18
Location: #db_error in: select usr.location from sucko_member where usr.id=63;
Contact:
Post
by Nerdz » 01 Apr 2008, 08:56
Glad I could help, if you need any other help feel free to ask
Give a man a fish, you feed him for one day.
Learn a man to fish, you feed him for life.