?
Solved

Input validation in Qbasic

Posted on 2002-05-13
6
Medium Priority
?
598 Views
Last Modified: 2008-03-10
Dear Programmers

Could you please supply me with a piece of code in QBasic to answer the following problem:

Declare an array N which contains 30 cells of integer type and prompt the user to read in 30 integers between 0 and hundred.

Validity of input between 0 and 100 is important.  
0
Comment
Question by:cybernursery
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 22

Expert Comment

by:CJ_S
ID: 7006591
Homework?
0
 

Author Comment

by:cybernursery
ID: 7009532
50 DIM N(30)
100 For I= 1 to 30
200 Input M(I)
300 If M(I)>=30 AND M(I)<=100 THEN 500
400 Print "Out of Range"
500 Next I


Well this is my piece of code, is it correct?
0
 
LVL 2

Accepted Solution

by:
TrueDrake earned 300 total points
ID: 7032760
Hi,

I haven't used QBasic for many years, however your code seeems more of a GS Basic type. I'd try:

Option Base 1
DIM N(30) as Integer
For I= 1 to 30
   Input M
   If M>0 Or M<100 THEN
        Print "Out of Range"
   Else
        N(i)=M
   End If
Next I

Enjoy

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Expert Comment

by:CJ_S
ID: 7032883
GW Basic, not GS
0
 
LVL 24

Expert Comment

by:SunBow
ID: 7063788
> between 0 and 100 is important

IMO that means 0 is invalid as is 100.

So,,, I'd say any two digit number is valid.
Better to be positive, than to be censor

Any one digit number is also OK

0 isn't really a number, you can't hold it or add it to anything to generate something creatively new

(or can you?)
0
 
LVL 24

Expert Comment

by:SunBow
ID: 7063800
>>     "300 If M(I)>=30 AND M(I)<=100 THEN 500"

This is really simple enough to test, something all programmers should do.

It has been awhile, but as I recalll, basic permits entry for non-positive integers such as -1 and 0

>> "input between 0 ..."

as such, input of 1 to 29 should succeed and be permitted. Have you tried?

>>  ' If M>0 Or M<100 THEN Print "Out of Range"   '

It has been awhile for my tired eyes, but I'd revisit the directions of angle brackets if the sample inputs misbehave on the output end

Or switch logic, and only print out the good ones. With only 30 inbound, that won't be too many lines
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Progress

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question