I need help with this assignment

November 26, 2010 at 23:28:22
Specs: Windows XP
Hargrove Foods wants to have a program that allows entry of prices until the users enters -9999 for the price. These prices must be stored in an array. Then your program will print out each price (excluding the -9999) and the total price to charge added together displayed as a running total. The running total must be displayed after the input of all the numbers as shown below. The last value represents the total price.

Sample program execution:

Please enter price of the item (-9999 to exit): 5.35
Please enter price of the item (-9999 to exit): 8.25
Please enter price of the item (-9999 to exit): 10.75
Please enter price of the item (-9999 to exit): 7.35
Please enter price of the item (-9999 to exit): -9999
Price ---- Total
5.35 -------5.35
8.25 -------13.6
10.75 ------24.35
7.35 ---------31.7

I need help adding the total to the prices.
Here is what I have so far;

' Declare variables and array
DIM price(1000) AS STRING
DIM count AS INTEGER
DIM numitems AS INTEGER
dim total(1000) as string
count = 1
' Priming read entered into an array
INPUT "Enter a price (-9999 to exit): ", price(count)
' Continue until a sentinel value is added
DO WHILE price(count) <> "-9999"
' Add 1 to the counter used as the subscript
count = count + 1
' Read the next item
INPUT "Enter a price (-9999 to exit): ", price(count)
LOOP
' Since the last item entered is the sentinel value subtract 1 from the number
' of items to exclude the sentinel value.
numitems = count - 1
PRINT
PRINT
PRINT

PRINT "Prices entered" , "total",
' Print out the items
FOR count = 1 TO numitems

NEXT count

sleep
END


See More: I need help with this assignment

Report •


#1
November 27, 2010 at 00:34:14
You should say what help you need.


=====================================
Life is too important to be taken seriously.

M2


Report •

#2
November 27, 2010 at 01:04:44
I need help adding the total to the prices.
Here is what I have so far;

' Declare variables and array
DIM price(1000) AS STRING
DIM count AS INTEGER
DIM numitems AS INTEGER
dim total(1000) as string
count = 1
' Priming read entered into an array
INPUT "Enter a price (-9999 to exit): ", price(count)
' Continue until a sentinel value is added
DO WHILE price(count) <> "-9999"
' Add 1 to the counter used as the subscript
count = count + 1
' Read the next item
INPUT "Enter a price (-9999 to exit): ", price(count)
LOOP
' Since the last item entered is the sentinel value subtract 1 from the number
' of items to exclude the sentinel value.
numitems = count - 1
PRINT
PRINT
PRINT

PRINT "Prices entered" , "total",
' Print out the items
FOR count = 1 TO numitems

NEXT count

sleep
END


Report •

#3
November 27, 2010 at 07:50:35
I need help adding the total to the prices.
Probably because you're storing the prices as Strings, instead of something sane like Integer.

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
November 27, 2010 at 08:56:55
As you are entering currency values I would declare the price as a currency data type. If you don't want the currency symbol then a single precision floating point at least. The total should be a numerical variable as well unless you want to do a number to string conversion.

Stuart


Report •

#5
November 27, 2010 at 17:22:08
The issue I am having is with the accumulator not working as i would want it to.
sum=sum+price(1000)

My mistake I originally had " " around the -9999 which forced me to make price as a string when it should have been a single. But here is the new code.

' Declare variables and array
DIM price(1000) AS single
DIM count AS INTEGER
DIM numitems AS INTEGER
dim total(1000) as single
dim sum as single
count = 1
' Priming read entered into an array
INPUT "Enter a price (-9999 to exit): ", price(count)
' Continue until a sentinel value is added
DO WHILE price(count) <> -9999
' Add 1 to the counter used as the subscript
count = count + 1
' Read the next item
INPUT "Enter a price (-9999 to exit): ", price(count)
LOOP
numitems = count - 1
PRINT
PRINT
PRINT
sum=sum+price(1000)
PRINT "Prices" , "total"
' Print out the items
FOR count = 1 TO numitems
PRINT price(count) , sum
NEXT count

sleep
END


Report •

#6
November 27, 2010 at 17:37:55
never mind got it

' Declare variables and array
DIM price(1000) AS single
DIM count AS INTEGER
DIM numitems AS INTEGER
dim total(1000) as single
dim sum as single
dim x as integer
count = 1
' Priming read entered into an array
INPUT "Enter a price (-9999 to exit): ", price(count)
' Continue until a sentinel value is added
DO WHILE price(count) <> -9999
' Add 1 to the counter used as the subscript
count = count + 1
' Read the next item
INPUT "Enter a price (-9999 to exit): ", price(count)
LOOP
numitems = count - 1
sum=0

PRINT
PRINT
PRINT

PRINT "Prices" , "total"
' Print out the items
FOR count = 1 TO numitems
sum=sum+price(count)
PRINT price(count) , sum
NEXT count

sleep
END


Report •


Ask Question