floating point exception occurs...Why??? I'm using integers
Hi, all
Instead of posting my entire code, I'll just post the snippet where the error pops up. I appreciate your responses.
Here is my main code:
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
GasMileage *myGas = [[GasMileage alloc]init];
int miles = 0;
//grabbing the value stored at the address of miles variable
int *milepointer= &miles;
//Obtaining user input
NSLog(@"How many miles did you drive?");
scanf ("%i", &miles);
//setting user input values
[myGas setmilesdriven: *milepointer];
//calculate mpg
[myGas calcmpg];
[pool drain];
return 0;
}
Here's the snippet of code where the error pops up:
@implementation GasMileage
-(void) calcmpg
{
//calculating mpg
int gallons = 0;
int *gallonpointer = &gallons;
*gallonpointer = gallonsused;
NSLog(@"How many gallons did you use?");
scanf ("%i", &gallons);
int total;
total = milesdriven/gallonsused;
NSLog(@"Your mpg: %i", total);
//I did not paste remaining code for this method call
Here's my output from Terminal:
Last login: Fri Mar 19 11:48:54 on ttys001
karen-haqs-imac:~ karenhaq$ /Users/karenhaq/Objective-C/GasMileage/build/Debug/GasMileage ; exit;
2010-03-19 11:52:10.895 GasMileage[55145:10b] How many miles did you drive?
40
2010-03-19 11:52:21.721 GasMileage[55145:10b] How many gallons did you use?
10
Floating point exception
logout