Computer Science Canada Totaling all values of randint problem |
Author: | troy14 [ 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 |
Author: | Insectoid [ 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. |
Author: | troy14 [ 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 |
Author: | Insectoid [ 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. |
Author: | troy14 [ 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? |
Author: | Insectoid [ 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:
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? |
Author: | troy14 [ 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 |
Author: | mirhagk [ 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:
and for turing you can even do [ syntax="turing"] your turing code here [ /syntax] to get blocks that look like:
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 |