(This is a restatement of a problem brought up in a previous thread.) This program outputs two numbers each time a button is pushed. The first number is random. The second number should be 1 greater than the first. However, this is not the case (as can be seen by pushing the button more than once).
BATester.h:
BATester.m:
Here is my output:
The first time the button is pushed, no problem, but all subsequent pushes print out the same number twice. What is going on?
(If you are worried about memory leaks, please address this issue in my post entitled "Memory leaks".)
BATester.h:
Code:
#import <Cocoa/Cocoa.h>
@interface BATester : NSObject {
}
- (IBAction)button:(id)sender;
@end
BATester.m:
Code:
#import "BATester.h"
@implementation BATester
- (IBAction)button:(id)sender {
NSNumber* theNumb;
theNumb=[[NSNumber numberWithFloat:rand()] retain];
NSLog(@"%f and %f", [theNumb floatValue],([theNumb floatValue]+1));
}
@end
Here is my output:
Code:
[Session started at 2010-10-16 18:32:35 -0700.]
2010-10-16 18:32:42.181 Tester[419:10b] 16807.000000 and 16808.000000
2010-10-16 18:32:43.275 Tester[419:10b] 282475264.000000 and 282475264.000000
2010-10-16 18:32:45.762 Tester[419:10b] 1622650112.000000 and 1622650112.000000
2010-10-16 18:43:34.338 Tester[419:10b] 984943680.000000 and 984943680.000000
The first time the button is pushed, no problem, but all subsequent pushes print out the same number twice. What is going on?
(If you are worried about memory leaks, please address this issue in my post entitled "Memory leaks".)