URGENT! Please help me with this program! Code glitch!

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
emmylb
Newbie
Posts: 1
Joined: Sat Apr 21, 2012 8:31 am

URGENT! Please help me with this program! Code glitch!

Post by emmylb »

Okay, so here are the instructions my teacher gave us:
Write a program to assist a shopkeeper to price his goods. The prices are set according to ranges of cost of the products (the ranges are: $0-$9.99, $10-$19.99, >$20), each range having a markup percentage that changes from one shopping season to another. So, the program needs the current markups for the cost ranges (put into an array), the product names and their costs. These are supplied in the form of a file of information created by the shopkeeper, which will be read by the program. (See the products.dat file for an example of the data file.) The program will then print a table where each row holds the product name, the cost, the markup and the price (in columns ? will require formatted writes).

Here is the pseudocode he wants us to use:
declare array (markups)
open data file
print program header
read markups from file into an array
print table headings
loop until end-of-file
read product name and cost from the file
if cost < $10 then
profit = cost * markups(1)
else if cost <$20 then
profit = cost * markups(2)
else
profit = cost * markups(3)
end if
price = cost + profit
print product table row: name, cost, profit, price
end loop
stop

Here is what the products.dat file contains:
.06 .08 .12
"Dirt Dobber Drops" 2.24
"Mulberry Muffin" 3.10
"Cranberry Cake" 16.75
"Persimmon Parfait Party Pack" 24.55

Here is my messed up code:
REM
DIM markups(3)
OPEN "E:\products.dat" FOR INPUT AS #1
PRINT "This program will assist the user in pricing goods."
INPUT #1, markups(1)
INPUT #1, markups(2)
INPUT #1, markups(3)
PRINT markups(1)
PRINT markups(2)
PRINT markups(3)
PRINT "Product Cost Markup Price"
DO
INPUT #1, product$(1)
INPUT #1, product$(2)
INPUT #1, product$(3)
INPUT #1, product$(4)
INPUT #1, cost(1)
INPUT #1, cost(2)
INPUT #1, cost(3)
INPUT #1, cost(4)
IF cost < 10 THEN
profit = cost * markups(1)
ELSEIF cost < 20 THEN
profit = cost * markups(2)
ELSE
profit = cost * markups(3)
END IF
price = cost + profit
INPUT #1, price
PRINT USING "\ \"; product$(1)
PRINT USING "\ \"; product$(2)
PRINT USING "\ \"; product$(3)
PRINT USING "\ \"; product$(4)
PRINT USING "##.##"; cost(1)
PRINT USING "##.##"; cost(2)
PRINT USING "##.##"; cost(3)
PRINT USING "##.##"; cost(4)
PRINT USING "##.##"; profit
PRINT USING "##.##"; price
CLOSE #1
LOOP UNTIL EOF(1)
STOP

I would very much appreciate any help with how to fix my code. Please show me actual code as I am not familiar with QBasic terminology. Thank you all so much for your time and help!
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

The file data should have commas between the values or have each value on a separate line. INPUT # can read them either way. No spaces

.06,.08,.12
"Dirt Dobber Drops",2.24
"Mulberry Muffin",3.10
"Cranberry Cake",16.75
"Persimmon Parfait Party Pack",24.55
.06
.08
.12
"Dirt Dobber Drops"
2.24
"Mulberry Muffin"
3.10
"Cranberry Cake"
16.75
"Persimmon Parfait Party Pack"
24.55
The INPUT # variable must be the same type as the value. Quoted values are strings with $ suffix and rest need no variable suffix as they are SINGLE. They MUST be read in the order they are placed in the file!
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
Post Reply