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

Username:   Password: 
 RegisterRegister   
 Turing Troubles with Counters, Averages and Loops.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Vorpal




PostPosted: Fri Dec 19, 2008 12:36 am   Post subject: Turing Troubles with Counters, Averages and Loops.

I am experiencing a great deal of trouble with a Turing assignment. It must take 10 weights entered by the user and then find the average weight of all 10 weights and round it to one decimal place. I'm really lost as to how I can do that, any help would really be appreciated.
Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Fri Dec 19, 2008 1:00 am   Post subject: RE:Turing Troubles with Counters, Averages and Loops.

Break down the assignment into steps. Use simple steps, so they're easy to convert directly into code.

Step 1: Accept 10 weights as input from the user. You'll need 10 variables, or preferably, one array with 10 entries. You can either code this as:
- input 1
- input 2
- input 3...
or as
for i : 1..10
input i
end for

though the second option only works if you're using arrays.

Step 2: You need to average all the weights. The formula for average is (sum of all the numbers to be averaged) / (number of numbers to be averaged). We know that it'll be something divided by 10, so you just need to figure out how to determine the sum.

Step 3:: You need to make sure that when you output the calculated sum, you round to 1 decimal place.

If you don't understand how to do any of these steps, you need to ask your teacher for help.
syntax_error




PostPosted: Fri Dec 19, 2008 3:42 am   Post subject: RE:Turing Troubles with Counters, Averages and Loops.

you don't need 10 vars nor do you need an array of elements here, all you have to do with the weights is add them no? Thus, ONE var can hold that value and as the user can enter how many he or she wants to enter, use another var like count to keep track of how many entries if you ever had to make it a general programme, not limited to 10 entries.

As for steps 2 and 3 outlined by DemonWasp are fine.
DemonWasp




PostPosted: Fri Dec 19, 2008 3:37 pm   Post subject: RE:Turing Troubles with Counters, Averages and Loops.

...good point. I hope that I'd have noticed that when I went to code it, but no guarantees.
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  [ 4 Posts ]
Jump to:   


Style:  
Search: