Author |
Message |
troy14
|
Posted: Thu Sep 20, 2012 6:54 pm Post subject: 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 |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: Thu Sep 20, 2012 7:17 pm Post subject: 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. |
|
|
|
|
![](images/spacer.gif) |
troy14
|
Posted: Thu Sep 20, 2012 7:24 pm Post subject: 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 |
|
|
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: Thu Sep 20, 2012 7:42 pm Post subject: 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. |
|
|
|
|
![](images/spacer.gif) |
troy14
|
Posted: Thu Sep 20, 2012 7:49 pm Post subject: 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? |
|
|
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: Thu Sep 20, 2012 8:06 pm Post subject: 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
|
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? |
|
|
|
|
![](images/spacer.gif) |
troy14
|
Posted: Thu Sep 20, 2012 8:19 pm Post subject: 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 |
|
|
|
|
![](images/spacer.gif) |
mirhagk
|
Posted: Thu Sep 20, 2012 8:46 pm Post subject: Re: Totaling all values of randint problem |
|
|
by the way you can use [ code] your code here [ /code] (without the spaces) to get blocks that look like:
code: |
var num:int
var text := "hello world!"
|
and for turing you can even do [ syntax="turing"] your turing code here [ /syntax] to get blocks that look like:
Turing: |
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 |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
|