Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

going from one loop to another, newbie here. 1

Status
Not open for further replies.

speedingpenguin

Programmer
Jan 31, 2004
1
US
I'm taking qbasic in school and we have to write a pice of software that manages an auction. Pretty much we're free to be creative and do what we want as long as the software works and you could be a complete idiot and not screw the program up. Right now it starts out fine, but has trouble in the middle. I have it ask for the name of the item, the starting price, the first bid which i made a do until loop so that the first bid has to be greater than the starting price, that works all fine....but then i want it to go to 'next bid' and only accept bids that are higher than the previous high bid. It jumps immediatly from after you enter a valid number for the 'first bid' to what i want it to do at the end....say the high bid, ask for the high-bidders name, and then say '(name) has won the (item)'

here is the code i have so far, if you can tell me what i'm doing wrong i would appreciate it bigtime. I want to get one step ahead in the class, and if i could bring in a stable and pretty reliable program on monday i would be happy.

CLS

PRINT "**AUCTION**"
PRINT " "
PRINT "To stop auction, enter 0"
PRINT " "
PRINT "Enter name of item "
INPUT item$
PRINT " "
PRINT "Enter starting price: "
INPUT minn

DO UNTIL low > minn
PRINT "Enter first bid: "
INPUT low
LOOP


DO UNTIL bid = 0
PRINT "Enter next bid"
INPUT bid
IF bid > min THEN bid = min
IF bid < min THEN bid = invalid
IF bid > min THEN bid = max
LOOP


PRINT &quot;AUCTION ENDED&quot;
PRINT &quot; &quot;
PRINT &quot;High bid: &quot;; max
PRINT &quot;Enter name of high bidder: &quot;
INPUT name$
PRINT name$; &quot; has won the &quot;; item$
END

 
Your second loop &quot;DO until bid=0&quot; starts with bid equaling 0 because it's never defined or input so that loop would seem to be ignored in effect.

I would suggest, inputing the bid one time right before the
second do loop. That way, bid will have something to start with then if it is zero it will go to the &quot;AUCTION ENDED&quot;

otherwise it will loop and ask again for another bid.

There are other ways to do it, but that would be the simplest modification for the program you have.

i.e. have an input for the bid in addition to the input for the bid within the do loop.
OR,
change the loop to:
DO
.
.
.
LOOP UNTIL BID=0
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top