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
Solved

Input validation in Qbasic

Posted on 2002-05-13
6
553 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

A short article about problems I had with the new location API and permissions in Marshmallow
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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…

856 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