• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

QBASIC HELP

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

WeezleXX89

Member
Joined
Mar 14, 2006
Location
Earth
ASSIGNMENT
Design a defining diagram and algorithm that will
prompt an operator for a student’s serial number and the student’s exam score out of 100. Your program is then to match the exam score to a letter grade and print the grade to the screen. Calculate the letter grade as follows:

Exam score Assigned grade

90 and above A

80–89 B

70–79 C

60–69 D

below 60 F

HERES WHAT I HAVE
10 CLS
20 INPUT "type out student's serial number"; serial#
30 INPUT "what was percentage on your test"; test#
40 IF test# >= 90 THEN PRINT "you got an A"
50 IF test# >= 80 THEN PRINT "you got a B"
60 IF test# >= 70 THEN PRINT "you got a C"
70 IF test# >= 60 THEN PRINT "you got a D"
80 IF test# >= 50 THEN PRINT "you got a F"
90 END

My question is if i put the grade as 100, it says "you got an A, you got a B, you got a C, you got a D, you got an F. How do fix this? I want it to work as if i were to type the grade as a 93 i only want it to say you got an A.
Thanks
 
workin on it, however, try typing a grade of 45.
look at your code, you print if the number is greater than 90 then greater than 80, etc.
 
As long its in QBASIC language, a jump is basically ok, unless you're using a structure language like C or pascal, then thats different story.

Weezle, if you don't like to use jump, just enhance the querying statement like this :

At line -> 50 IF (test# >= 80) AND (test# < 90) THEN PRINT "you got an B".

.. and so on.

Of course this is not efficient design cause it has to go through all of them.
 
Last edited:
Figured it,
1. Think about what specifically needs done; e.g. what EXACT range do you need for the grade of an A (B, C, D, F)
2. Look in the Help function for the function you need to add AND add it in.
3. Again, consider all the grades that are available for each letter and specify ONLY that range for the IF THEN function. This will eliminate stray PRINTs.
Good Luck.
(It's WAY TOO EASY for me to just tell you. If you plan on doing any programming later Qbasic is an obscenely easy programming language and you need to know some kind of basics. [pun intended])
EDIT
bugger on bing for posting before I had finished.
 
To eliminate goto function in qbasic you could use subset IF THEN ELSE functions
IF test#>=90 then print "A" else if test# >=80 then print "b" else if test#>=70 then etc.etc.
this would limit it to running the minimum amount and keeping it all in one line.
 
I seem to remember from middle school that there was a "CASE" operator in QBASIC, that if it matches the first case, the rest are ignored.
IF THEN ELSES should also work.
 
I also recall that one, it would work better.
WeezleXX89, just a great hint for qbasic,
move the cursor over the operator and press f1, instant help.
 
Yes i did the ElSEIF command and it worked great thanks guys if i need more help ill post what i need help for.
 
Back