Getting the division error likes others have had


#1

Hi,

I’m getting the "EXC_ARITHMETIC (code=EXC_I368)… Error when trying to run the code. I’m not sure whats wrong with it, any help would be great.

Thanks!

[code]#import <Foundation/Foundation.h>
#import “Employee.h”
#import “Asset.h”

int main(int argc, const char * argv[])
{

@autoreleasepool {
    
    //Create an array for employees
    NSMutableArray *employees = [[NSMutableArray alloc] init];
    
    for (int i = 0; i < 10; i++){
        
        
    //Create an instance of Person
    Employee *person = [[Employee alloc] init];
    //Employee *countNumber = [[Employee alloc] init];
    
    
    
    //Give the instance variables and interesting values
    [person setWeightInKilos:90 + i];
    [person setHeightInMeters:1.8 - i/10.0];
    [person setEmployeeID:i];
    }
    
    //Create 10 Assets
    
    for (int i = 0; i < 10; i++){
       
        // Create an Asset
        Asset *asset = [[Asset alloc] init];
        
        //Give it an interesting label
        NSString *currentLabel = [NSString stringWithFormat:@"Laptop %d", i];
        [asset setLabel:currentLabel];
        [asset setResaleValue:i * 17];
        
        //Get a random number between 0 and 9 inclusive
        NSUInteger randomIndex = random() % [employees count];
        
        //Find that employee
        Employee *randomEmployee = [employees objectAtIndex:randomIndex];
        
        //Assign the asset to the employee
        [randomEmployee addAssetsObject:asset];
    }
    NSLog(@"Employees: %@", employees);
    
    NSLog(@"Giving up ownership of employee");
    
    [employees removeObjectAtIndex:5];
    
    NSLog(@"Giving up ownship of array");
    
    employees = nil;
    
    
    //Call the BMI method
   
        

}
return 0;

}
[/code]


#2

Never mind, it looks like I forgot the line of code that added objects to the array, which is why Dividing by 0 came up, due to it being empty.