Why is it saying illegal instruction ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
28th Jun 2019, 12:20 PM
Foxie
Foxie - avatar
8 Answers
+ 2
You can fix that by declaring the functions as void: void easy() {...} void min() {...} void hard() {...} void insane() {...}
28th Jun 2019, 12:43 PM
Seb TheS
Seb TheS - avatar
+ 3
#CODER I tried flushing the input buffer to stop causing the infinite loop when given a wrong format by putting fflush(stdin) inside the default switch statement. It worked though NB. I don't know why, but it only works when I use scanf to read the input instead of using cin
28th Jun 2019, 3:20 PM
Agent_I
Agent_I - avatar
+ 2
I suspect that the program behaves weird, because you declared the easy, min, hard and insane function to return an integer, but they don't return anything anyways.
28th Jun 2019, 12:35 PM
Seb TheS
Seb TheS - avatar
+ 2
There was also a risk for causing an infinite loop. When it asks for difficulty, and if wrong type of value was given, an infinite loop was caused.
28th Jun 2019, 2:20 PM
Seb TheS
Seb TheS - avatar
+ 2
I don't actually know. The problem is, when an integer is required, but unnumeric characters were given.
28th Jun 2019, 2:29 PM
Seb TheS
Seb TheS - avatar
+ 1
It worked !! Thanks !!
28th Jun 2019, 2:15 PM
Foxie
Foxie - avatar
+ 1
How to fix that ?
28th Jun 2019, 2:21 PM
Foxie
Foxie - avatar
+ 1
Hmm..weird
28th Jun 2019, 4:05 PM
Foxie
Foxie - avatar