Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Problems with user input
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
lucklesslily




PostPosted: Thu Nov 05, 2015 11:11 am   Post subject: Problems with user input

So I'm running into a couple problems with my program, it's calculating shipping time and cost using the weight and whether the package is international/domestic. Anyway, my problem is that I'm trying to error proof the weight input so that if someone puts in letters instead of numbers the program doesn't crash, but it's not really working...

put "And how much will your product be weighing? (In kg)"
loop %Weight Error Safe
get weightReply :*
%Weight Word Error Safe
if strrealok (weightReply)then
weight := strreal (weightReply)
%Weight Number Error Safe
elsif weight <=0 %Says variable not defined when letters in-putted
then
put "Input is not a number above 0."
exit when (weight >0)
end if
end loop

Furthermore, when you do put in a number, it doesn't continue with the rest of the program, it's just a bunch of blank space where you can enter more numbers. Embarassed
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Thu Nov 05, 2015 2:05 pm   Post subject: RE:Problems with user input

'variable not defined' means your variable has no value. You created the variable weight, but never assign it a number. But you have a line that says 'weight := strreal (weightReply)', so why does it still not have a value? Maybe there's a reason that line doesn't execute. Maybe it has something to do with your if statement structure.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: