Got a small problem here , I spent 2 days writing this with debugging sessions , alone, here is the thing its working and all but sometimes it just divide by 0 , I tried adding a
val2=//my random number generator.
but no luck .
and another thing is that what ever I do I cant restart the score after each stage completed.
for example ,
//diificulty stage chosen.
// first stage have score of more than 60 , pass to the next stage.
//next stage score should be 100 if u answer all questions , instead its 100 + prev score .
I did this and it works , tried it for 20 times and it never divides by 0.
is there a way I can shorten my double variable ?
because when it gives me something like 1/9 and I give it 0.11 it never gets it even if I put the full number which is 0.1111111111 .
here is the output .
Please choose the operation you want to practice today (+,-), or(/,*): /
Please enter the level of difficult (1 and up): 1
what is 6 / 8: 0.75
Incorrect!what is 6 / 8:
same thing happened with me with ( 1/9 ).
I completed all the other operations and they work perfectly , the stages too.
minor: its <ctime> and <cmath> you are using C language header files. They work, until they don't, it can cause problems.
as lastchance said you need to understand how the computer does integeer math.
first, 6/8 is smaller than 1, so it is truncated down to zero. 100/11 is 9, for the same reasons.
second, even if you change to doubles, your == is going to give trouble. some numbers cannot be represented exactly as doubles, so even if the human types in the correct answer, it will not match. I haven't memorized specific examples, you can find plenty on google, but it "like" if you computed 6/8 and the actual answer ways 0.7499999999999999998 but you typed 0.75 and it changed that to 0.7500000000000000000001 instead. Again, made up the numbers, but they are not equal, just very close ...
so you need to switch to doubles and then handle matching that with the user's input. a simple way to do that is simply to see if abs(userinput - calculated result) <= 0.001 (or whatever precision you expect).