mercredi 30 septembre 2015

Bug in a fixed If - Else statement

this is my first post in this site.

As the title says, I encountered a bug in an If - else if - else block of codes. What the problem is that, I am pretty confident that I have covered all 9 possible outcomes that there should be.

It is quite hard to explain more, so if you guys could take a look at my .cpp file and run it ( hopefully it runs because I used c++ on a mac), you may find an easier understanding of my problem.

source code cpp file

If you browse through my action();, in the else statement, I purposely displayed that you encountered a bug so just in case there were bugs, I'd be informed.

What I am trying to do is like this:

userinput | randomAImove | outcome

A             1           statement
A             2           statement
A             3           statement
D             1           statement
D             2           statement
D             3           statement
W             1           statement
W             2           statement
W             3           statement
else        1||2||3       statement

There are corresponding statements to each conditions met. 'A', 'W', 'D' are user input. I used a toupper command to force the compiler to just check on 'A' 'W' 'D'. However, the main problem I find is that, even if the toupper works(which I confirmed), the program displays the correct statement often but still somehow manages to bug even if the user(I tried it) input from A, W, D (not-case sensitive cuz of toupper).

Please just try it and after a few tries you may encounter it also. I wrote "you encountered a bug" if you ever do encounter it.

Please help me because I can't really see any other way to find the mistake. Maybe its in my plain sight but I can't seem to notice which one is it.

Thank you!

Aucun commentaire:

Enregistrer un commentaire