It looks like a possible divide by zero error.
There are a number of integers declared but not initialised.
At line 29
|
val1= rand () % val1 + 0;
|
va1
has not been initialised, its value is garbage. The expression
first calls the function rand(), then attempts to divide by val1. If val1 happens to be zero, that can give an error.
Actually, I think that line should use
difval
instead:
On a related area, since difval was not assigned an initial value and the switch-case statement does not have a default clause, then difval may still contain garbage.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
switch (dif)
{
case 1:
difval=50;
break;
case 2:
difval=100;
break;
case 3:
difval=150;
break;
default:
difval=100;
}
|
Also, the variable
attempts
has not been initialised, it contains garbage. It's a good idea to always
initialise variables before attempting to use them.
---------------------------------------------
How to start identifying problems such as this.
First compile with all warnings on, and pay attention to them.
From the Devc++ menu, select
tools->compiler options-> general
Check the box "add the following commands when calling the compiler:" and add the following:
-std=c++11 -Wall -Wextra -pedantic-errors |
Secondly, you can use the debugger to step through the code line by line to identify the exact point at which it crashes (in this case, at line 29).