I have numbers in an array, odd and even, I have to add the odd ones with one another and the even ones wit one another. I am very confused as to how to go about this because of the parameters and conditions given:
In my Adder.h file I have the following:
@interface ConditionalAdder : NSObject
- (instancetype)initWithNumbers:(NSArray *)numbers;
- (int)sumWithCondition:(NSString *)condition;
@end
In my Main.m file I have the following code:
#import "ConditionalAdder.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
ConditionalAdder *adder1 = [[ConditionalAdder alloc]
initWithNumbers:@[@1, @2, @3, @4, @5]];
NSLog(@"%i", [adder1 sumWithCondition:@"even"]);
NSLog(@"%i", [adder1 sumWithCondition:@"odd"]);
ConditionalAdder *adder2 = [[ConditionalAdder alloc]
initWithNumbers:@[@13, @88, @12, @44, @99]];
NSLog(@"%i", [adder2 sumWithCondition:@"even"]);
ConditionalAdder *adder3 = [[ConditionalAdder alloc]
initWithNumbers:@[]];
NSLog(@"%i", [adder3 sumWithCondition:@"odd"]);
}
return 0;
}
I know that this method:
- (int)sumWithCondition:(NSString *)condition;
Should return an integer, but what string am I supposed to pass through the parameter?
Aucun commentaire:
Enregistrer un commentaire