Qbasicnews.com

Full Version: Using the "ENTER" key to cause BASIC program to &q
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Got a little problem that is beyond my (very) remedial
QBasic skills that I would like some help with...

I have written a small grade averaging program that
works great for my wife's needs. There is one
refinement though that I just can't seem to figure
out. I know it can't be that difficult, but with my serious
lack of programming skills, I haven't been able to
solve this.

As the program is currently written, once I enter
however many grades that I want to average, I enter a
"-1" to get the program to then GOTO the averaging
subroutine.

Now the above works just fine, but I would prefer for
the program to do the average when I merely hit the
"enter" key without entering any grade.

I know that I can't just write something similar to this:

IF (grade = "") THEN GOTO AverageGrades

since this will cause a type mismatch error because
the program is looking for an integer to be entered
here for the grade variable. So while I sort of
understand WHY I can't do something similar to the
above, I can't figure out how to do what I want to do.

I know that I have come across a way to cause a
program to respond to a simple enter key press, but
doggone if I can remember how I saw it done!

Could someone please give me some clue as to how to
accomplish what I am trying to do?

Thanks...
Input values as text:

Code:
INPUT value$

Then check:

Code:
IF value$="" THEN GOTO Average

And then:

Code:
value! = VAL(value$)

Will translate the string to a number, stored in value!
Ever notice how single precision variables are always excited?
Writer1stus:

You mean like this?
Code:
CLS
DO
a = a + 1
PRINT a; "- ";
INPUT "", grade$
b = b + VAL(grade$)
LOOP UNTIL grade$ = ""
PRINT b / (a - 1)

Edit: Updated Program
Quote:Ever notice how single precision variables are always excited?
<--- thought that when he was a new programmer... Tongue
Or you can always initialize the variable that holds the input to zero when you're done with it, and then to see if you didn't enter anything, check it to see if it's still zero. Also, zero is the default value of any numeric variable.
Thanks for the various suggestions to my problem. They were all much appreciated. I especially appreciated the code that whitetiger0990 posted here. Not only did his few lines of code help to solve my problem, but accomplished what my SEVERAL lines of code did and in a much more simple yet elegant way.

Whitetiger0990, if you are reading this... tell me you are not 12 years old! (... the "0990" makes me wonder if you were born in Sept. of 1990!)

Regardless, thanks for the help from all of you. I was sooo tired of beating my head agains the wall trying to slove this.
No I just put 0990 because it sounded cool 8)
Oh and incase i was... So what?

Also I tried to put it in an array... Didn't work so well. It took longer. And if you tried to not make it take as long is didn't work.
whitetiger0990... there is no "so what"... it would only drive home the fact that I am entirely too far removed from what little basic I learned in college and the fact that even a young programmer still in middle school can not only solve my problem but in a few minutes throw out a few lines of code that virtually encompass the whole of my programming efforts that I labored on for... well, I really rather not say how long I worked on it. I'm just greatful for the help.

In other words it was meant to be a sort of back handed compliment along with a poor attempt at humor. Certainly not a "dis". Sorry if I offended you.
Oh... Well I don't like giving away my exact age my i am <= 14

belive it if you wish

EDIT: i am in middleshool too
EDIT2: I will have been programming for about 1 year this fall.
Pages: 1 2