Qbasicnews.com
May 26, 2020, 05:09:44 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1] 2
  Print  
Author Topic: Using the "ENTER" key to cause BASIC program to &q  (Read 3956 times)
Writer1stus
New Member

Posts: 3


« on: May 31, 2003, 03:57:14 PM »

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...
Logged
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #1 on: May 31, 2003, 03:59:40 PM »

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!
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
seph
Na_th_an
*****
Posts: 1915



« Reply #2 on: May 31, 2003, 04:35:48 PM »

Ever notice how single precision variables are always excited?
Logged

earn.
whitetiger0990
__/--\__
*****
Posts: 2964



WWW
« Reply #3 on: May 31, 2003, 05:02:40 PM »

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
Logged


[size=10]Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.[/size]
pr0gger
I hold this place together
*****
Posts: 775


« Reply #4 on: May 31, 2003, 07:06:36 PM »

Quote from: "seph"
Ever notice how single precision variables are always excited?

<--- thought that when he was a new programmer... Tongue
Logged

size=9]"To announce that there must be no criticism of the president, or that we are to stand by the president, right or wrong, is not only unpatriotic and servile, but is morally treasonable to the American public." -- Theodore Roosevelt[/size]
Zack
*/-\*
*****
Posts: 3974



WWW
« Reply #5 on: May 31, 2003, 11:37:01 PM »

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.
Logged

f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Writer1stus
New Member

Posts: 3


« Reply #6 on: June 01, 2003, 10:19:45 PM »

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.
Logged
whitetiger0990
__/--\__
*****
Posts: 2964



WWW
« Reply #7 on: June 01, 2003, 10:33:04 PM »

No I just put 0990 because it sounded cool  Cool
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.
Logged


[size=10]Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.[/size]
Writer1stus
New Member

Posts: 3


« Reply #8 on: June 01, 2003, 11:14:58 PM »

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.
Logged
whitetiger0990
__/--\__
*****
Posts: 2964



WWW
« Reply #9 on: June 01, 2003, 11:17:24 PM »

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.
Logged


[size=10]Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.[/size]
Zack
*/-\*
*****
Posts: 3974



WWW
« Reply #10 on: June 02, 2003, 12:29:13 PM »

I'm 12, been progging for about 8-10 months. Doesn't matter how old you are. It probably gets harder as you get older. Smiley
Logged

f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
whitetiger0990
__/--\__
*****
Posts: 2964



WWW
« Reply #11 on: June 02, 2003, 04:52:44 PM »

My parents don't want me to tell my exact age. I'm 11 - 14 in middleschool.


_________________
"C" is a cool letter.
Logged


[size=10]Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.[/size]
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #12 on: June 02, 2003, 05:40:16 PM »

Perhaps the smiley will tell us.  :lol:
Logged

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.
whitetiger0990
__/--\__
*****
Posts: 2964



WWW
« Reply #13 on: June 02, 2003, 05:57:51 PM »

Quote from: "Agamemnus"
Perhaps the smiley will tell us.  :lol:

?
Logged


[size=10]Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.[/size]
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #14 on: June 02, 2003, 06:46:18 PM »

YOUR SMILEY.
Logged

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.
Pages: [1] 2
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!