Need Cash Register and Test Averageing Program Help
Author |
Message |
wenchman
|
Posted: Sun Nov 21, 2004 2:45 pm Post subject: Need Cash Register and Test Averageing Program Help |
|
|
I've been doing homework handed out by my teacher for a while, and am stumped on two questions. I was wondering if anyone could just give me the answer, because no matter what I do, it's wrong.
1. Create a pgrogram which calculates teh average mark in a group of tests. Assume al tests are out of ten. Make the user enter the mark for each test in the group one at a time. When there are no more tests to input, enter the number "-1" and print out the average.
a) Make sure users can only enter numbers 1-10
b) Make it so the program can handle users entering no marks.
2. Create a program that will act as a simple cash register. It will accept the name of an item and the cost. The user will enter an item name "done" to signify that the customer is finished. The program will output a bill with the sub-total, PST, GST and total price.
a) Make it so the user can only enter positive values.
b) Display all items and their prices in the bill.
Any help on this will be greatly appreciated. I just can't seem to get these two last questions of my homework.
Here's one of mine, if it'll help, its my attempt to the first one:
code: |
var mark, average, subtotal :real:=0
var count:int:=0
loop
loop
put "Type in a test mark between 1-10 and 45 to exit: "..
get mark
exit when mark >=0 and mark <=10 or mark = -1
put "Invalid."
end loop
subtotal:= subtotal + mark
count = count + 1
exit when mark = -1
end loop
loop
exit when count = 0
average := subtotal/count
exit
end loop
|
The other one is even worse |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Sun Nov 21, 2004 3:27 pm Post subject: (No subject) |
|
|
Quote:
subtotal:= subtotal + mark
count = count + 1
exit when mark = -1
you should exit for -1 before adding it to the total... else your total will be 1 less and divided by 1 more
Quote:
loop
exit when count = 0
average := subtotal/count
that doesn't make sence... exit when will never happen, your count starts at 1 because of the statement above. Why is average being calculated inside the loop? just drop the 2nd loop, only keep the average := line |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
wtd
|
Posted: Sun Nov 21, 2004 3:31 pm Post subject: (No subject) |
|
|
One of your big problems is that you get each mark, but you never accumulate those anywhere. |
|
|
|
|
![](images/spacer.gif) |
wenchman
|
Posted: Sun Nov 21, 2004 3:41 pm Post subject: (No subject) |
|
|
Oh, alright thanks. Can you guys please help me answer the 2nd question, I really have no idea - we just started the turing unit ![Sad Sad](http://compsci.ca/v3/images/smiles/icon_sad.gif) |
|
|
|
|
![](images/spacer.gif) |
cool dude
![](http://www.taylorstrategicmarketing.com/images/king.jpg)
|
Posted: Sun Nov 21, 2004 3:47 pm Post subject: (No subject) |
|
|
which one is question #4? there are only 2 questions as i see it |
|
|
|
|
![](images/spacer.gif) |
wenchman
|
Posted: Sun Nov 21, 2004 3:53 pm Post subject: (No subject) |
|
|
cool dude wrote: which one is question #4? there are only 2 questions as i see it
Sorry bout that, I said number 4 because there are 4 on my sheet and 4 is actually 2 here ![Embarassed Embarassed](images/smiles/icon_redface.gif) |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Sun Nov 21, 2004 4:12 pm Post subject: (No subject) |
|
|
use two arrays, one for item name, one for it's price. Keep a counter of how many items you have entered (similar to how you did in #1)
then to display the bill, just print out item's name from the array and its coresponding price.
add up the prices into subtotal (using a for loop) and total from the price array and display that as well |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
wenchman
|
Posted: Sun Nov 21, 2004 4:14 pm Post subject: (No subject) |
|
|
tony wrote: use two arrays, one for item name, one for it's price. Keep a counter of how many items you have entered (similar to how you did in #1)
then to display the bill, just print out item's name from the array and its coresponding price.
add up the prices into subtotal (using a for loop) and total from the price array and display that as well
Whats an array? ![Embarassed Embarassed](http://compsci.ca/v3/images/smiles/icon_redface.gif) |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
wenchman
|
Posted: Sun Nov 21, 2004 8:21 pm Post subject: (No subject) |
|
|
Can someone give me a corrected version of my program? :s I'm really confused ![Neutral Neutral](http://compsci.ca/v3/images/smiles/icon_neutral.gif) |
|
|
|
|
![](images/spacer.gif) |
wtd
|
Posted: Sun Nov 21, 2004 8:37 pm Post subject: (No subject) |
|
|
wenchman wrote: tony wrote: use two arrays, one for item name, one for it's price. Keep a counter of how many items you have entered (similar to how you did in #1)
then to display the bill, just print out item's name from the array and its coresponding price.
add up the prices into subtotal (using a for loop) and total from the price array and display that as well
Whats an array? ![Embarassed Embarassed](http://compsci.ca/v3/images/smiles/icon_redface.gif)
http://www.compsci.ca/v2/viewtopic.php?t=1117 |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
|
|
|
![](images/spacer.gif) |
wenchman
|
Posted: Sun Nov 21, 2004 9:04 pm Post subject: (No subject) |
|
|
Thanks alot.. |
|
|
|
|
![](images/spacer.gif) |
Viper
![](http://compsci.ca/v3/uploads/user_avatars/20678142424cb7690e076fe.jpg)
|
Posted: Fri Nov 26, 2004 3:32 pm Post subject: (No subject) |
|
|
this is the same as his basicly but a lil more simple
put"Enter tag price please"
get cost
%>>>>>>>>>>>>>
tax:= cost*0.15
total:=cost+tax
put "Tax total is"," ",tax
put "And total is"," ",total
%>>>>>>>>>>>>>
loop
put"Enter amount of cahsgiven"
get cashgive
%>>>>>>>>>>>>>
if cashgive<total then
put"Sorry you did not give enough money for your perchase"
cls
else
cashback:=cashgive-total
put "Here is your change"," ",cashback
exit
end if |
|
|
|
|
![](images/spacer.gif) |
|
|