Solved

Input validation in Qbasic

Posted on 2002-05-13
6
538 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
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 100 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
A short article about a problem I had getting the GPS LocationListener working.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
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…

813 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now