
-----------------------------------
Smarties102
Wed May 18, 2011 6:34 am

Help with arrays in Turing!! Grade 10 programming.
-----------------------------------
What is it you are trying to achieve?
Basically this is the outline of the program..
Write a program which allows the user to create, store, and retrieve values in an array. The program will first ask the user for the length of the array (make sure you check if the length is an integer). Then, you will display a menu for the user to make modifications to the array. The commands are ?set?, ?get?, ?count?, and ?replace?:

Menu
1.	Set value
2.	Get value
3.	Count frequency of value
4.	Replace value
Case 1: Set value. Ask the user for a value (any value), and an index (make sure it is an integer) to store that value into. Reprint the array using braces and commas, for example: {1, 2, 3, 4} Replacing one thing at a time. 
Case 2: Get value. Ask the user for an index (make sure it is an integer), and output the value in the array at that index.
Case 3: Count frequency of value. Ask the user for a value, and output how many times that value appears in the array.
Case 4: Replace value. Ask the user for a value to replace, and a value to replace it. Your program will replace any and all instances in the array with the new value.Reprint the array using braces and commas, for example: {1, 2, 3, 4} Replacing all.



What is the problem you are having?
I don't understand how to do the cases. 


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)


Please specify what version of Turing you are using
Turing 4.1.1


-----------------------------------
mirhagk
Wed May 18, 2011 4:48 pm

RE:Help with arrays in Turing!! Grade 10 programming.
-----------------------------------
Just a question, by any value, would it mean just integers or letters too?

And basically just work each of those 4 examples out, you have the structure done.

How would you retrieve the value of a piece of the array?
How would you set a value of a piece of the array?
How would you count how many there are of a value in the array? (think about how you would do this in real life, it's the same way)
How would you replace a value in the array? (Again think about what steps there are to this)

-----------------------------------
Smarties102
Thu May 19, 2011 7:23 am

Re: Help with arrays in Turing!! Grade 10 programming.
-----------------------------------
Thank you! I got it after thinking about it, but I would like to know if its better to use an if statement or case?

-----------------------------------
HRI
Fri May 20, 2011 8:07 am

RE:Help with arrays in Turing!! Grade 10 programming.
-----------------------------------
If statements should be used for quick comparisons, but if there's quite a few specific things the condition could be then use a case. Basically if you look in your code and see:

if ...
then
    ...
elsif ...
then
    ...
elsif ...
then
    ...
elsif ...
then
    ...
else
    ...
end if

A case would sum that up quite nicely.

case  of
   label :
       
   label 
       
   label :
       
end case

