
-----------------------------------
Nai
Fri Jun 12, 2009 6:11 pm

User can crash my program by entering a letters instead of numbers
-----------------------------------
What is it you are trying to achieve?
I am in the process of making an rpg game for my Grade 10 Info. Tech. class. In my game, there is a bank, which the user may enter and withdraw/deposit money. I am trying to eliminate any possiblility that the user will be able to crash the program by entering a letter or other key instead of a number when they are trying to withdraw/deposit their money.


What is the problem you are having?
When the player of my game enters the bank and tries to deposit or withdraw money, they are able to crash my program by inputting a letter or any other non-numeric key.


Describe what you have tried to solve this problem
I have already solved the problem of the keyboard queue having left-over input from the player's movement into the store (the player uses the arrow keys to move), so that when I use my get command to allow the user to input the amount of money that they wish to withdraw/deposit, their Up Arrow presses are not displayed. This was done using a conditional loop, an "exit when not hasch", and a getch command.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Here is my game file. The section for the player's activities in the bank begin at line 1419.



Please specify what version of Turing you are using
I am using version 4.1.1 of Turing.


Thank you for any help you can provide.

-----------------------------------
BigBear
Fri Jun 12, 2009 6:29 pm

RE:User can crash my program by entering a letters instead of numbers
-----------------------------------
Look at strintok

http://compsci.ca/holtsoft/doc/strintok.html

-----------------------------------
Kharybdis
Fri Jun 12, 2009 10:38 pm

Re: User can crash my program by entering a letters instead of numbers
-----------------------------------
what he is saying is that for any basic error trapping in your program, you have to make everything a string, even if what you're asking is actually a number.

example of how this would be implemented:


%For integers...
var banknum : string
loop
    put "Please enter your bank account number:"
    get banknum
    exit when strintok (banknum)
    put "That is not valid input!"
end loop

put strint (banknum) / 2, " < ---- your number divided by 2"

%for reals...
loop
    put "Please enter the percentage with decimal places:"
    get banknum
    exit when strrealok (banknum)
    put "that is not a valid input!"
end loop

put strreal (banknum) / 2, " 