Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can someone help figure out this code?
#1
Hi

I'm new to programming in general and starting with QBasic. I've been using the book SAMS TY Beginning Programming and can't get past the section on using the SELECT CASE statement.

The code printed below keeps causing me problems: Can anyone undertsand what's wrong?

' Prints a description based on user's number
INPUT "How many years have you been in school"; years

SELECT CASE years
CASE 1
PRINT "This is your first year"
CASE 2
PRINT "This is your second year"
CASE 3
PRINT "This is your third year"
CASE 4
PRINT "This is your fourth year"
CASE ELSE
PRINT "You did not enter 1, 2, 3, or 4"
END SELECT
END


I keep getting an error message saying that it is illegal to use a statement between CASE SELECT and CASE 1 commands. :o

Any help will be gratefully accepted.

netwarriorgizmo :roll:
Reply
#2
copy, delete, and paste back your code in qb.

The only time that would make an error is if you put anything between SELECT CASE and the first case statement, and you didn't.

(works for me)
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#3
I'll give it a try!

Thanks for posting your reply.

netwarriorgizmo
Reply
#4
I copied your code, compiled it, and it runs fine.

Try re-typing the SELECT CASE years and then the CASE 1 statements again. Maybe you had a bad unprintable character somewhere on either of the lines. That can happen.
*****
Reply
#5
Thanks. I'll try again!

netwarriorgizmo :???:
Reply
#6
Hi

I've tried the code by copying it, deleting it and repasting it yet still it doesn't work.

I've also tried completely re-writing it from scratch (three times now) and still the compiler keeps notifying me with the same error message!

Anyone got any further ideas? :o

All other code in the same book works perfectly.

netwarrirogizmo.
Reply
#7
try possibly making it a number in a do loop. i personally would start with a string to check for input and then convert it to a number

Code:
years$ = ""
do until years$ <> ""
input "Enter the amount of years you have been in school: ", years$
loop

years% = int(years$) 'that just converts it

select case years%
case 1
yada yada yada
end select
end

not absolutely positive it will work, but its worth a try
This is the end of everything, you are the end of everything." -Slipknot - Everything Ends

"GOD HATES US ALL!!" -Slayer - God Hates Us All
Reply
#8
Try putting a DEFINT A-Z statement at the front of your program.
*****
Reply
#9
what does that defint a-z do anyway?
This is the end of everything, you are the end of everything." -Slipknot - Everything Ends

"GOD HATES US ALL!!" -Slayer - God Hates Us All
Reply
#10
DEFINT A-Z makes all undefined variables integers instead of the default DEFSNG A-Z (singles)
am an asshole. Get used to it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)