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

Username:   Password: 
 RegisterRegister   
 Beginner turing help- Accumulators?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
jadelinanne




PostPosted: Mon Oct 29, 2012 2:48 pm   Post subject: Beginner turing help- Accumulators?

What is it you are trying to achieve?
I have to make a program where i print out credit card monthly statements for customers.
The program asks for the number of purchases, then ask the customer to type in the amounts of their purchases one at a time and will accumulate this into a running total.
The company has a 20 cent service charge for each purchase made.



What is the problem you are having?
I can't add the cost of the purchases with the service charge because the second purchase always overwrites the first one and so on.


Describe what you have tried to solve this problem



Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)

var customerName, business, address : string
var purchases, cost, sc : real
var service := 0.20
var minimum := 0.15
var total := 0
var serviceFee : real

put " "
put "Hello. Please enter your name"
get customerName : *
put " "
put "Please enter your business or work place"
get business : *
put " "
put "Please enter your address (street,city,province/state,postalcode)"
get address : *
put " "
put "Please enter the total number of purchases"
get purchases
sc := service * purchases
serviceFee := minimum * purchases

loop
total := total + 1
put " "
put "Please type in the cost of each item"
get cost
exit when total = purchases
end loop

var amountDue := purchases + service

put " "
put sc : 3 : 2
put amountDue : 10 : 2
put serviceFee


How do i get the costs to add up properly?
Thanks! Very Happy
Please specify what version of Turing you are using
Sponsor
Sponsor
Sponsor
sponsor
mirhagk




PostPosted: Mon Oct 29, 2012 3:13 pm   Post subject: RE:Beginner turing help- Accumulators?

You can just get a temporary value and add it to cost, similar to how you are doing the total := total + 1 part
jadelinanne




PostPosted: Mon Oct 29, 2012 3:18 pm   Post subject: RE:Beginner turing help- Accumulators?

It has to be the cost the user enters :S
mirhagk




PostPosted: Mon Oct 29, 2012 3:30 pm   Post subject: RE:Beginner turing help- Accumulators?

yes, so you can have a new variable in the loop that is called tempCost or something, and get that from the user, and then add it to the total cost.
jadelinanne




PostPosted: Mon Oct 29, 2012 3:36 pm   Post subject: RE:Beginner turing help- Accumulators?

D: I'm new to all this stuff, can you please show me what you mean? I tried to put in a new variable in the loop but it just messed other stuff up :S
mirhagk




PostPosted: Tue Oct 30, 2012 10:03 am   Post subject: RE:Beginner turing help- Accumulators?

I would suggest going over the teacher's previous lectures on variables before you try loops. Make sure you understand variables completely before you even start to do loops.

It's extremely important you understand all the concepts, and I'm having a hard time explaining it without giving you the entire code. I/we can help you understand, but we can't just give you the answer, you need to work that out on your own, otherwise you won't ever learn how to program correctly.

Think about what creating a variable does, think about what getting a variable does, and try with a very basic example to do the following:
code:
Get 2 numbers from the user, and add them together

When you can do that then show the code here and I can help you get to the next step.
chipanpriest




PostPosted: Wed Oct 31, 2012 7:21 pm   Post subject: RE:Beginner turing help- Accumulators?

loop
var1 := var1 + cost
var2 := var2 + 20
end loop
var1 + var2
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  [ 7 Posts ]
Jump to:   


Style:  
Search: