Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Need Cash Register and Test Averageing Program Help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
wenchman




PostPosted: 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. Sad


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
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: 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 Confused

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? Confused just drop the 2nd loop, only keep the average := line
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
wtd




PostPosted: 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.
wenchman




PostPosted: 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
cool dude




PostPosted: 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
wenchman




PostPosted: 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 Razz Embarassed
Tony




PostPosted: 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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
wenchman




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
wenchman




PostPosted: 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
wtd




PostPosted: 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


http://www.compsci.ca/v2/viewtopic.php?t=1117
Tony




PostPosted: Sun Nov 21, 2004 8:40 pm   Post subject: (No subject)

you own me 30 seconds Laughing
code:

var array_name : flexible array 1 .. 0 of string
var array_price : flexible array 1 .. 0 of real
var text : string
var price : real
loop
    put "enter name"
    get text
    exit when text = "done"
    put "enter price for ", text
    get price
    new array_name, upper (array_name) + 1
    new array_price, upper (array_price) + 1
    array_name (upper (array_name)) := text
    array_price (upper (array_price)) := price
end loop
cls
put "your bill is"
for i : 1 .. upper (array_name)
    put array_name (i), "\t", array_price (i)
end for


eh, yeah... don't use that - that's cheating. Just an example.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
wenchman




PostPosted: Sun Nov 21, 2004 9:04 pm   Post subject: (No subject)

Thanks alot..
Viper




PostPosted: 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
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 13 Posts ]
Jump to:   


Style:  
Search: