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

Username:   Password: 
 RegisterRegister   
 An odd way to do something.... Help?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh pageAdd this topic to your bookmarks (CTRL-D) View next topic
Author Message
4sak3nX




PostPosted: Mon Mar 08, 2010 10:34 am   Post subject: An odd way to do something.... Help?

So im have to make a test averager that allows the user to determine how many test to be used.

Below is the exact terms of what im supposed to do:

"Create a test marks averager, that will work for any number of tests. It should first ask for the number of tests to be averaged, then ask for each of the test marks. It then displays the average of the tests."

So far this is all i have for the code...:

Turing:

var count : real
var answer : real
var mark : real

put "Please enter the amount of tests to be averaged: " ..
get count

for x : 1 .. count
    put "Please enter the test mark: " ..
    get mark
end for



what am i supposed to do next?
 
Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Mon Mar 08, 2010 11:13 am   Post subject: RE:An odd way to do something.... Help?

You have to calculate an average. Get a piece of paper and pencil, so you can do this on paper (trust me, this makes it easier than doing it on the computer).

An average is calculated as the sum of a series of numbers, divided by the number of numbers. Or:

code:

a + b + c + d + e + ... / N


Where there are N of a, b, c, d, e ...

Note that you do not have to store all of a, b, c, d, e, ... , you only have to store their sum, because eventually that's all you need.

So, keep a running total of the marks input so far, until the user is done inputting marks. Divide that total by the number of marks input.
 
Turing_Gamer




PostPosted: Mon Mar 08, 2010 12:35 pm   Post subject: Re: An odd way to do something.... Help?

(Test 1 + Test 2 + Test 3 ... + Test N) / Number of Tests

Very simple. It is like finding the median.
 
USEC_OFFICER




PostPosted: Mon Mar 08, 2010 12:39 pm   Post subject: RE:An odd way to do something.... Help?

You mean the mean. The median is the value which is closest to the middle. The mode is the value that appears the most.
 
Turing_Gamer




PostPosted: Mon Mar 08, 2010 12:47 pm   Post subject: Re: An odd way to do something.... Help?

Sorry I meant that...

Here is how you can construct it
Turing:
for i : 1 .. count
    sum := sum + test (i)
end for

Your_Average := sum / count

put " Your average of " + intstr (count) + " test(s) is " + intstr (Your_Average) + "!!!"


Is there something called 'realstr'?
 
sportygal1994




PostPosted: Wed Mar 17, 2010 2:08 pm   Post subject: Re: An odd way to do something.... Help?

I would solve it this way.
Of course declard them all first, and initizalize the total at 0.
Turing:

for x:1..number
get mark
total:=total+mark
end for

put " the average is ", total/number


This I believe is a summing notation. Not sure what the official name is, but it should work.
 
chrisbrown




PostPosted: Wed Mar 17, 2010 3:14 pm   Post subject: Re: An odd way to do something.... Help?

Summation notation is the consice way of writing what this program calculates. It would be expressed as:


CodeCogsEqn.gif
 Description:
Calculating average, where where x(i) is the ith number read from the user
 Filesize:  595 Bytes
 Viewed:  2081 Time(s)

CodeCogsEqn.gif


 
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh pageAdd this topic to your bookmarks (CTRL-D) View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: