Hi,
I seem to struggle quite a lot when it comes to casting and I was creating a lottery application which generates 6 random numbers then displays the results in a textfield (label).
I get the following warning, 'assignment makes pointer from integer without a cast'.
I'm a bit stumped as what to do and how and where to make the appropriate cast.
The code is below:
Appcontroller.h
Appcontroller.m
Also, is this code the correct way to go about this task?
Thanks
I seem to struggle quite a lot when it comes to casting and I was creating a lottery application which generates 6 random numbers then displays the results in a textfield (label).
I get the following warning, 'assignment makes pointer from integer without a cast'.
I'm a bit stumped as what to do and how and where to make the appropriate cast.
The code is below:
Appcontroller.h
Code:
#import <Cocoa/Cocoa.h>
@interface AppController : NSObject {
IBOutlet NSButton *btnGetNumbers;
IBOutlet NSButton *btnClear;
IBOutlet NSTextField *txtNumbers;
}
-(IBAction)getNumbers:(id)sender;
-(IBAction)clear:(id)sender;
@end
Appcontroller.m
Code:
#import "AppController.h"
@implementation AppController
-(IBAction)getNumbers:(id)sender
{
NSNumber *number1 = [[NSNumber alloc] init];
NSNumber *number2 = [[NSNumber alloc] init];
NSNumber *number3 = [[NSNumber alloc] init];
NSNumber *number4 = [[NSNumber alloc] init];
NSNumber *number5 = [[NSNumber alloc] init];
NSNumber *number6 = [[NSNumber alloc] init];
number1 = random() % 49 + 1; //error below each line
number2 = random() % 49 + 1; //
number3 = random() % 49 + 1; //
number4 = random() % 49 + 1; //
number5 = random() % 49 + 1; //
number6 = random() % 49 + 1; //
NSString *string = [NSString stringWithFormat:@"Your numbers are: %i, %i, %i, %i, %i, %i", number1, number2, number3, number4, number5, number6];
[txtNumbers setStringValue:string];
[number1 release];
[number2 release];
[number3 release];
[number4 release];
[number5 release];
[number6 release];
[super dealloc];
}
-(IBAction)clear:(id)sender
{
[txtNumbers setStringValue:@""];
}
@end
Also, is this code the correct way to go about this task?
Thanks