2

I have been recently using the Xcode console tool to build simple programs. What I am trying to do is set a value say "x" equal to a division of variables. Xcode seems to work with adding and subtracting but not with setting variables equal to division of variables. Here is my code for further reference:

scanf("%ix^2+%ix+%i", &h, &i, &j);

            k = h/m; <---- Error

            l = i - n;

            m = h/k; <---- Error

            n = i - l;

            l = j/n; <---- Error

        NSLog(@"(%ix+%i)(%ix+%i)", k, l, m, n);
John Ryan
  • 137
  • 1
  • 5

1 Answers1

2

EXC_ARITHMETIC (SIGFPE) It may happens because of various conditions like divide by zero, integer overflow, etc., and in your case it is most likely integer divide by zero I guess.

Edit: The problem is that it is not and exception, its a signal error so you can't handle it by exception handling. You need to find out a way for signal handling. See the accepted answer of this question C++ : Catch a divide by zero error for more information.


In an overall aspect division by zero is a logical error, you shouldn't let that happen at first so instead handling it, better try such type of situation should not occur.

Community
  • 1
  • 1
NIlesh Sharma
  • 5,445
  • 6
  • 36
  • 53