D
David Casey
I'm working on a program for my C++ class and have it all written and
working except for one part. I need to compare two numeric variables to
determine decimal accuracy between them. For example:
pi = 3.14159...
mynum = 3.14226...
The mynum is accurate to 2 decimal places compared to pi. I could figure
this out easy with a char array since I could just take a character one at
a time from each array and compare it. However with a numeric variable I'm
coming up short trying to figure this out.
I've had other ideas, but I can't seem to make any of them work right so I
figured I'd go back to my original idea which is to figure out where in
memory the variable is stored using a pointer. Then read each digit in
individually and compare it with the same digit in the same position in the
other variable. If they are equal, add 1 to the precision variable. If
they're not, then leave the loop and the accuracy is whatever precision is
equal to.
I've spent quite a few hours tonight looking in all the C++ books I own and
searching both the Internet and Usenet but to no avail. I suppose I'm
looking for a way to do what I was able to in BASIC all those years ago
like the peek command which would return whatever was in a specific memory
location.
I'm not looking to be given an answer to my problem, just a nudge in the
right direction so I can find it myself. Thanks to any help anyone can
provide.
Dave
--
You can talk about us, but you can't talk without us!
US Army Signal Corps!!
http://www.geocities.com/davidcasey98
Remove IH8SPAM to reply by email!
working except for one part. I need to compare two numeric variables to
determine decimal accuracy between them. For example:
pi = 3.14159...
mynum = 3.14226...
The mynum is accurate to 2 decimal places compared to pi. I could figure
this out easy with a char array since I could just take a character one at
a time from each array and compare it. However with a numeric variable I'm
coming up short trying to figure this out.
I've had other ideas, but I can't seem to make any of them work right so I
figured I'd go back to my original idea which is to figure out where in
memory the variable is stored using a pointer. Then read each digit in
individually and compare it with the same digit in the same position in the
other variable. If they are equal, add 1 to the precision variable. If
they're not, then leave the loop and the accuracy is whatever precision is
equal to.
I've spent quite a few hours tonight looking in all the C++ books I own and
searching both the Internet and Usenet but to no avail. I suppose I'm
looking for a way to do what I was able to in BASIC all those years ago
like the peek command which would return whatever was in a specific memory
location.
I'm not looking to be given an answer to my problem, just a nudge in the
right direction so I can find it myself. Thanks to any help anyone can
provide.
Dave
--
You can talk about us, but you can't talk without us!
US Army Signal Corps!!
http://www.geocities.com/davidcasey98
Remove IH8SPAM to reply by email!