Solved

Input validation in Qbasic

Posted on 2002-05-13
6
512 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
Comment Utility
Homework?
0
 

Author Comment

by:cybernursery
Comment Utility
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
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 22

Expert Comment

by:CJ_S
Comment Utility
GW Basic, not GS
0
 
LVL 24

Expert Comment

by:SunBow
Comment Utility
> 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
Comment Utility
>>     "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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
zeroFront challenge 7 70
Changing the installation path of this MSI 5 84
bigHeights  challenge 13 55
Excel object stays open 19 64
Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
This article will show, step by step, how to integrate R code into a R Sweave document
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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 …

763 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

9 Experts available now in Live!

Get 1:1 Help Now