Help with program

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
Midnightw

Help with program

Post by Midnightw »

I am trying to create a program that based on your score will give you a certain message. I did it a couple of years back but I dont remember how its bone in basic

example
less than or equal to 500 1 message

greater then 500 but not more than 1000 a different message

greater then 1000 another entierly different message

what do I do?
RayBritton
Veteran
Posts: 109
Joined: Thu Feb 10, 2005 12:38 pm

Post by RayBritton »

this might help:

Code: Select all

if score =<500 then 
     print "Message 1"
elseif score =<1000 then 
     print "Message 2"
elseif score > 1000 then 
     print "Message 3"
end if
you probably will want something more complex than just print "Message 1"

=< means equal to and/or lower
=> means equal to and/or higher
> means higher only
< means lower only
User avatar
Zim
Veteran
Posts: 98
Joined: Mon Dec 05, 2005 4:31 pm
Location: Wisconsin, USA
Contact:

Less than or equal to

Post by Zim »

I always write "less than or equal to" this way:

Code: Select all

 if count <= 500 then do stuff
Either way works. I just think it looks better than =<.
--- Zim ---
--- Time flies like an arrow, but fruit flies like a banana ---
User avatar
Zim
Veteran
Posts: 98
Joined: Mon Dec 05, 2005 4:31 pm
Location: Wisconsin, USA
Contact:

Case Structure

Post by Zim »

Oh, and... you can also do it with case structure like this:

Code: Select all


select case score
  case is < 500
       ...do low score stuff
  case 500 to 1000 
       ...do medium score stuff
  case is > 1000
       ...do high score stuff
end select

Also, if you use a "case" structure that can possibly have a "no case" case, you need to provide a "case else" like this:

Code: Select all


select case score
   case is < 500
       ...lo score stuff
   case 500 to 1000
       ...do other stuff
   case else
       ...neither of the above was true
end case

I think case structure reads real nice.
--- Zim ---
--- Time flies like an arrow, but fruit flies like a banana ---
RayBritton
Veteran
Posts: 109
Joined: Thu Feb 10, 2005 12:38 pm

Post by RayBritton »

i was going to have a else statement but that would be impossible as every number is covered
Post Reply