
-----------------------------------
troy14
Thu Sep 20, 2012 6:54 pm

Totaling all values of randint problem
-----------------------------------
What is it you are trying to achieve?
Im trying to total all the values of a randint


What is the problem you are having?
I cannot total all the values of a randint, i just get a funny character at the end of my program


Describe what you have tried to solve this problem
I have tried to find a solution but haven't found one


Please specify what version of Turing you are using
I am using 4.1.1 of turing

-----------------------------------
Insectoid
Thu Sep 20, 2012 7:17 pm

RE:Totaling all values of randint problem
-----------------------------------
Show us the code you've written so far and we'll point you in the right direction.

-----------------------------------
troy14
Thu Sep 20, 2012 7:24 pm

Re: Totaling all values of randint problem
-----------------------------------
what im trying to do is get a running total.

this is my code so far

var mark : int
var total : int
var average : int

put "Test#              Mark"
for test : 1 .. 10
    randint (mark, 1, 30)
    put test : 3, mark : 17, "/30"
end for

-----------------------------------
Insectoid
Thu Sep 20, 2012 7:42 pm

RE:Totaling all values of randint problem
-----------------------------------
Well, you haven't done anything with 'total' yet. You're going to want to set it to 0 to start. Then you're going to want to start adding things to it, probably inside a loop.

-----------------------------------
troy14
Thu Sep 20, 2012 7:49 pm

Re: Totaling all values of randint problem
-----------------------------------
how would i start adding things to it? where would put total to be able to start being added to?

-----------------------------------
Insectoid
Thu Sep 20, 2012 8:06 pm

RE:Totaling all values of randint problem
-----------------------------------
Figuring that out is the point of the assignment. 

How do you add to something? With the + operator. 

var sum = a + b //sum is now a + b

var sum = sum + a //sum is now itself plus a

var sum += a //this is just a nicer way to write sum = sum + a. It does the same thing.

Try running this:

[code]
var count = 0
for x : 0..9
    count += 1
    put count
end for
[/code]

This will add 1 to count and output it 10 times. Now how do you suppose you would add a random number to count instead of 1?

-----------------------------------
troy14
Thu Sep 20, 2012 8:19 pm

Re: Totaling all values of randint problem
-----------------------------------
thanks! i got it working.

code:
var mark : int
var total : int
var average : int

total := 0
put "Test#              Mark"
for test : 1 .. 10
    randint (mark, 1, 30)
    put test : 3, mark : 17, "/30"
total +=mark
    end for
put total

-----------------------------------
mirhagk
Thu Sep 20, 2012 8:46 pm

Re: Totaling all values of randint problem
-----------------------------------
by the way you can use 
var num:int
var text := "hello world!"


It makes it a lot easier for others to help you, and it will mean you'll be more likely to get a response, and faster
