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

Username:   Password: 
 RegisterRegister   
 Help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Thanos




PostPosted: Mon Sep 09, 2002 8:46 pm   Post subject: Help

Hey guys, I need some help with this thing im working on. It's the beginning of school so don't worry, this is not a school project. I'm just trying to get ahead in class. Anyway, my question is what is the code for averaging a bunch of numbers? what's the code for sum?
I'm trying to create a program that will average some school marks.
Thanks for taking your time to read this. 8)
Sponsor
Sponsor
Sponsor
sponsor
Dan




PostPosted: Tue Sep 10, 2002 10:47 am   Post subject: help

ok here is a progame that will avg any number of numbers:

code:


var numofnums : int
var curentnum : int
var total : int := 0

put "how many nus to avg?"
get numofnums

for i : 1 .. numofnums

    put "plz put in number ", i
    get curentnum

    total += curentnum

end for

put "the avg of thess nums is: ", total div numofnums


now i dont know how much you know about turing so here are some of the basciks:

to add numbers:

code:

var a:int %decare 1st var
var b:int %decare 2nd var
var total:int

a := 2 %set a to 2
b := 2 %set b to 2

total:= a+b %add a with b and store the value in total

put total %print the aswer on the screen


avg is done like in math by adding the numbers up then diveding by the amout of nums.

if you need any more help or anything fell free to post any time.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Tony




PostPosted: Tue Sep 10, 2002 4:51 pm   Post subject: grr

Dan, its the beginning of school and the guy is asking you how to add numbers? You just give him some code with for loops and no documentary... Could have used arrays as well Mad

Well just keep in mind that you got to remember at what knowledge level people are.

As for Thanos, good luck with your programming Exclamation Dan will be posting some 'insparational' source code up on the board cuz I'LL BE DOING VB instead.

Oh, Dan, nice quote you got there... BTW, I'm fine now Wink
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Dan




PostPosted: Tue Sep 10, 2002 7:30 pm   Post subject: sory

ok, may be i shode have made it more basick.


ok here is some math stuff in turing:

+ add's two numbers

- subtractes two numbers

:= asings a value to a var

+= adds a number to a var

-= subtraces a number from a var

div diveds a number by another

* mutiplyes a number by another

puting it togther:

lets say we whont to disay an awers to 5 + 5 on the screen, we coude do this:

code:

put 5 + 5


to add two vars together and put it on the screen you coude do this:

code:

var a:int:=5
var b:int:=5

put a + b


to add two vars together and soter that number in a var:

code:

var a:int:=5
var b:int:=5
var c:int

c:= a + b


all this can be done the same using +, -, *, /, and div


so to do a simpe version of the avg thing you can do this:

code:

var n1:int:= 100
var n2:int:= 10
var n3:int:= 50
var avg:int

avg:= (n1 + n2 + n3) div 3

put avg



ok, if you have any more quesions about this plz post.

p.s. is that ok with you tony, lol
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Thanos




PostPosted: Fri Sep 13, 2002 5:06 pm   Post subject: (No subject)

Hey guys, thanks for all the help. Surprised
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  [ 5 Posts ]
Jump to:   


Style:  
Search: