Valid and Invalid Input...
Author |
Message |
Hunter007
|
Posted: Tue Jan 13, 2004 9:11 pm Post subject: Valid and Invalid Input... |
|
|
Hey I'm working on a couple programs right now and I want it to recognize valid and invalid input. For example if the put is "Enter small or large: " and they enter an incorrect spelling or something else, how can I set it that it will clear what the user entered and let them type it in again? Any help would be greatly appreciated. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
AsianSensation
|
Posted: Tue Jan 13, 2004 10:07 pm Post subject: (No subject) |
|
|
code: | loop
cls
locate (1, 1)
put "hello, please enter your name: "
get name
if name = "AsianSensation" then
put "good job, you entered the correct name"
exit
end if
end loop
|
like this? |
|
|
|
|
|
Hunter007
|
Posted: Wed Jan 14, 2004 4:39 pm Post subject: (No subject) |
|
|
Thank you that does help, but my prog isn't working for some reason Think you can take a look and see whats wrong?
code: |
const GSTper : real := 0.07
const PSTper : real := 0.08
var PST : real
var GST : real
var item : string
var number : int
var cost : real
var total : real
var totalPST : real := 0
var totalGST : real := 0
var totalsub : real := 0
var grandTotal : real := 0
var reply : string (1)
var continue : string
loop
put "Press any key to continue or 'q' to quit..."
put ""
getch (reply)
exit when reply = "q"
loop
cls
put " * *************************************** *"
put " * When finished type in 'Done'as Product. *"
put " * *************************************** *"
put ""
put "PRODUCT: " ..
get item : *
put ""
exit when item = "done" or item = "Done"
loop
locate (7, 1)
put " " : 12
locate (7, 1)
put "QUANTITY: " ..
get number
put ""
if number < 0 then
put "You entered correctly!"
put ""
exit
end if
if number > 0 then
put "You entered incorrectly!"
put ""
end if
end loop
loop
locate (9, 1)
put " " : 16
locate (9, 1)
put "PRICE: $" ..
get cost
if cost < 0 then
put "You entered incorrectly!"
put ""
end if
end loop
cost := cost * number
PST := cost * PSTper
GST := cost * GSTper
total := cost + GST + PST
totalsub := totalsub + cost
totalPST := totalPST + PST
totalGST := totalGST + GST
grandTotal := grandTotal + total
cls
end loop
cls
delay (1000)
put "The customer's purchase comes to..."
put ""
put "SUBTOTAL : $ ", totalsub : 6 : 2
put "PST : $ ", totalPST : 6 : 2
put "GST : $ ", totalGST : 6 : 2
put "TOTAL : $ ", grandTotal : 6 : 2
put ""
put "Press any key to continue..." ..
getch (reply)
cls
totalsub := 0
totalPST := 0
totalGST := 0
grandTotal := 0
end loop
|
|
|
|
|
|
|
shorthair
|
Posted: Wed Jan 14, 2004 4:48 pm Post subject: (No subject) |
|
|
Here is your fixed code , it wont be teh wa y you want it but your problem was that you never exited you loops , so it just kept reruning and aslo your > and < were backwards so the input was never correct unless you entered and negative number i added 2 exit statement to exit when cost >0 you can change those exits to your liking , loops need these statements or they keep running |
|
|
|
|
|
|
|