AllExperts > Experts 
Search      

Qbasic, Quickbasic

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More Qbasic, Quickbasic Answers
Question Library

Ask a question about Qbasic, Quickbasic
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About QBasic Mac
Expertise
QBasic was designed to be run on a DOS operating system. I can answer most any question about programming in general and QBasic and DOS in particular, at a level understandable to the average novice programmer. As QBasic was designed to introduce people to the principals of programming and not designed to be a developer's language, I am unable to answer questions regarding how to write programs to do Windows type functions or advanced graphics. In particular, I answer no questions regarding VISTA as that system does not support QBasic. Sorry you have VISTA!

Experience
I have been writing BASIC programs since the VIC-20 was introduced and QBasic programs as soon as it came out. I have participated on QBasic forums such as the classic forum at www.qbasic.com for years and thus have lots of experience working with people with limited knowledge of QBasic. Samples of my works: A telephone-book type program which is notable because of the way it remembers what the user enters and is difficult to "break" by entering bogus information. A utility program that will scan a QBasic program and find all labels which were not used. A maze you will probably never solve, but you can watch the computer solve it! I know someone who solved one. V'GER, A fascinating game of concentration rather than motor skills. A generalized help SUB. You insert your help information and as a result, you have a help panel with navigable topics. Homework drill: You supply a data file of word-pairs and it asks questions and checks your answer. The "different" part is that if the answer to "What is the capital of the USA"?" is "Washington, D.C." it will accept slight variations like "Washington DC". A program where you enter a,b,c of aX^2 bX c=0 - Get roots The missing ARC SIN and ARC COS functions A Bowling Scorepad. You enter pins knocked down. See scores entered. A House Alarm Simulator. Shows INKEY$ working in main program while ON TIMER is stepping down time until alarm triggers. Demo which shows swapping screens, moving object with arrows, objects moving while awaiting input. A program you can start in two windows and which allows you to send messages back and forth. Well, you get the picture. The list goes on and on.

Organizations
Masons

Education/Credentials
BA Mathematics

Awards and Honors
PBK

 
   

You are here:  Experts > Computing/Technology > Basic > Qbasic, Quickbasic > Finding the highest / lowest number

Topic: Qbasic, Quickbasic



Expert: QBasic Mac
Date: 3/12/2008
Subject: Finding the highest / lowest number

Question
Hi, I am trying to find out how to print the highest and lowest number entered into a variable and its just bugging me.. I know its pretty simple but I'm just not getting the logic right.. here is my code.

'Define the fields

DIM intCount AS INTEGER
DIM strEmpName AS STRING
DIM intSaleNum  AS INTEGER
DIM sngSales AS SINGLE
DIM sngAvgSale AS SINGLE
DIM sngHighSale AS SINGLE
DIM sngLowSale AS SINGLE
DIM sngTotalSale AS SINGLE

'start Variables
intCount = 0
sngTotalSale = 0

'Get The Header Record
INPUT "What is the employee's name"; strEmpName
INPUT "What is the number of sales"; intSaleNum

'Check for no data

IF IntSaleNum <= 0 THEN
  sngSales = 0
  sngAvgSale = 0
  sngHighSale = 0
  sngLowsale = 0
ELSE
  'Process the sales
  DO   
     intCount = intCount + 1
     PRINT "what is the amount for Sale Number"; intcount;
     INPUT sngSales
     sngTotalSale = sngTotalSale + sngSales
     sngAvgSale = sngTotalSale / intSaleNum
     LOOP UNTIL intCount = intSaleNum
END IF


Answer
What you need is to put the calculations for hi/lo in your loop where I have marked "* You work out your homework here".

You'll note that I start with
   IF intCount = 1 THEN
       sngHighSale = sngSales
       sngLowSale = sngSales

That takes care of the case of the first number. If the user enters, for example, 45, then 45 is the High and the Low so far, right?

So you add code that tests if subsequent values are bigger than the current high and puts the new value there, if so. Same for the smaller.

You can do it!

Mac



' Define the fields
DIM intCount AS INTEGER
DIM strEmpName AS STRING
DIM intSaleNum  AS INTEGER
DIM sngSales AS SINGLE
DIM sngAvgSale AS SINGLE
DIM sngHighSale AS SINGLE
DIM sngLowSale AS SINGLE
DIM sngTotalSale AS SINGLE
' start Variables
intCount = 0
sngTotalSale = 0
' Get The Header Record
INPUT "What is the employee's name"; strEmpName
INPUT "What is the number of sales"; intSaleNum
' Check for no data
IF intSaleNum <= 0 THEN
 sngSales = 0
 sngAvgSale = 0
 sngHighSale = 0
 sngLowSale = 0
ELSE
 ' Process the sales
 DO
   intCount = intCount + 1
   PRINT "what is the amount for Sale Number"; intCount;
   INPUT sngSales
   sngTotalSale = sngTotalSale + sngSales
   sngAvgSale = sngTotalSale / intSaleNum
   IF intCount = 1 THEN
       sngHighSale = sngSales
       sngLowSale = sngSales
   ELSE
       * You work out your homework here
   END IF
 LOOP UNTIL intCount = intSaleNum
END IF
PRINT "Hi value: "; sngHighSale
PRINT "Lo value: "; sngLowSale
IF INPUT$(1) <> CHR$(27) THEN RUN ELSE END  

Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.