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

Username:   Password: 
 RegisterRegister   
 5+ bits the helper (please do not answer it for me, i only need help) I want to know how to do this next time.
Index -> Programming, Turing -> Turing Help
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Velocity




PostPosted: Tue Nov 08, 2011 8:31 pm   Post subject: RE:5+ bits the helper (please do not answer it for me, i only need help) I want to know how to do this next time.

And, i need 25 posts to add Karma, once i get 25, ill make sure to.
Sponsor
Sponsor
Sponsor
sponsor
Aange10




PostPosted: Tue Nov 08, 2011 8:39 pm   Post subject: Re: RE:5+ bits the helper (please do not answer it for me, i only need help) I want to know how to do this next time.

Velocity @ 8/11/2011, 7:31 pm wrote:
Two things @ Aange
1) How do you add numbers inside an array?
2) They also ask us to write a program that inputs a SIN number, checks to see if it is a valid SIN number and outputs an appropriate message (how would i input my program into that?)


1) If you haven't learned arrays yet, I'd suggest you wait for your teacher to explain it, or check out the Turing Walkthrough. However, to answer your question It would be like

code:

%Declare
var digit : array 1 .. 5 of int

%Add
digit(1) := digit(1) + digit(2)


2) Does it want the computer to generate the 9 digit number? If so, you could generate a random number (via Rand.Int() ) for each of the nine digits. [it would looks something like digit_1 := Rand.Int(1,9) ]

if you're getting the info, then use the get procedure for each digit.

You already know how to find out if the code is valid, run through the steps! As far as outputting the message, use the put procedure to output the message.
Velocity




PostPosted: Tue Nov 08, 2011 8:52 pm   Post subject: RE:5+ bits the helper (please do not answer it for me, i only need help) I want to know how to do this next time.

thank you.
Velocity




PostPosted: Tue Nov 08, 2011 8:53 pm   Post subject: RE:5+ bits the helper (please do not answer it for me, i only need help) I want to know how to do this next time.

And thank you for taking your time in helping me. Smile It is greatly appreciated Smile
Velocity




PostPosted: Tue Nov 08, 2011 8:54 pm   Post subject: RE:5+ bits the helper (please do not answer it for me, i only need help) I want to know how to do this next time.

And as i had said, here is your karma. Smile
Aange10




PostPosted: Tue Nov 08, 2011 8:58 pm   Post subject: RE:5+ bits the helper (please do not answer it for me, i only need help) I want to know how to do this next time.

You're very welcome, if you have any problems feel free to make a new thread. If I can't help you, there are people here who can.

And thanks for the karma!
Velocity




PostPosted: Tue Nov 08, 2011 8:58 pm   Post subject: RE:5+ bits the helper (please do not answer it for me, i only need help) I want to know how to do this next time.

This is what i have so far
[syntax ="turing"]

var digit : array 1 .. 9 of int
var step1 : real := 2468
var step2 : real := 4936
var evenSum : real
var oddSum : real
put "Step 1 is obvious..."
put " "
for ctr : 1 .. 9
put ctr
end for
put " "
put "I have reason to believe that the even values of numbers 1 - 9 are : 2, 4, 6, 8"
Time.Delay (10000)
cls
put "This is step 2."
step1 := step1 * 2
put step1
Time.Delay (5000)
cls
put "This is step 3."
evenSum := 4 + 9 + 3 + 6
put "The added value is: ",evenSum
Time.Delay (5000)
cls
digit := digit(1) + digit(3) + digit(5) + digit(7)
put digit

[/syntax]

it says that digit is wrong type?
Aange10




PostPosted: Tue Nov 08, 2011 9:10 pm   Post subject: RE:5+ bits the helper (please do not answer it for me, i only need help) I want to know how to do this next time.

because digit is an array, not an element of an array. digit(1) would be an (integer) element of the digit array. Where as digit is an array not the element of an array.



Also, I suggest you show you're work to the screen, and have the computer calculate everything for you. Instead of hard coding in answers, etc.
Sponsor
Sponsor
Sponsor
sponsor
Velocity




PostPosted: Tue Nov 08, 2011 9:19 pm   Post subject: RE:5+ bits the helper (please do not answer it for me, i only need help) I want to know how to do this next time.

I dont see what you mean.
Aange10




PostPosted: Tue Nov 08, 2011 9:23 pm   Post subject: RE:5+ bits the helper (please do not answer it for me, i only need help) I want to know how to do this next time.

Okay so Digit is an array. In this situation, Digit is an array 1 through 9 of integers. Meaning that this digit has 9 elements (1,2,3,4,5,6,7,8 and 9) that are integers.

We refer to these elements by calling them; Digit(1), Digit(2), Digit(3) ... we are calling the (1)st, (2)nd, (3)rd elements of the array (so on and so forth.)


Now when we define an array, we are working with it's elements. The (#)s.


So this error is telling us we can't define Digit, because it is an array NOT an element of an array.


If you are still confused, check out http://compsci.ca/v3/viewtopic.php?t=14333
Tony




PostPosted: Tue Nov 08, 2011 9:23 pm   Post subject: Re: RE:5+ bits the helper (please do not answer it for me, i only need help) I want to know how to do this next time.

What is the type of variable digit?
Velocity @ Tue Nov 08, 2011 8:58 pm wrote:
var digit : array 1 .. 9 of int

The type is "array 1 .. 9 of int"
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Beastinonyou




PostPosted: Tue Nov 08, 2011 10:15 pm   Post subject: Re: 5+ bits the helper (please do not answer it for me, i only need help) I want to know how to do this next time.

Just A Quick Note Regarding:

Step 2) Multiply the number by 2 to get a 5 digit number.


Have you considered what happens when a 4 digit number multiplied by 2 doesn't produce a 5 digit number?

2,468 x 2 = 4,936. I'm pretty sure 4,936 is a 4 Digit number.


This would mean that in order for your program to Continue, the Numbers in the even positions must be equal to or greater than 5,000, to produce a 5 digit number (10,000)
_______________________________

I hope this can give some insight into solving some of your steps. It all involves simple Problem Solving.

Turing:
var SIN : string
var even_Digits, odd_Digits : string := ""
var even : array 1 .. 4 of int
var odd : array 1 .. 5 of int
var even_Sum, odd_Sum : int := 0

%var random : int
%randomize
%randint (random, 100000000, 999999999)
SIN := "123456789" % random
for i : 2 .. 8 by 2      % 4 Times
    even (i div 2) := strint (SIN (i))  % Stores 2, 4, 6, 8.
    even_Sum += even (i div 2)  % Adds 2, 4, 6, 8
    even_Digits += SIN (i)      % Concatenates 2, 4, 6, 8 to get 4 Digits
    put even (i div 2), ", " .. % Display values inside even array
end for
put "Sum_E : ", even_Sum ..     % Display Sum of even numbers
put "  ", even_Digits           % Display the Concatenated 4 Digits
put skip

for i : 2 .. 10 by 2    % 5 Times
    odd (i div 2) := strint (SIN (i - 1)) % Stores 1, 3, 5, 7, 9.
    odd_Sum += odd (i div 2)    % Adds 1, 3, 5, 7, 9.
    odd_Digits += SIN (i - 1)   % Concatenates 1, 3, 5, 7, 9 to get 5 Digits
    put odd (i div 2), ", " ..  % Display values inside odd array
end for

put "Sum_O : ", odd_Sum .% Display sum of odd numbers
put "  ", odd_Digits        % Display the Concatenated 5 Digits
put SIN

% Need even/odd_Digits to be/act as an integer? use strint() [String to Integer]
Aange10




PostPosted: Wed Nov 09, 2011 12:04 am   Post subject: Re: 5+ bits the helper (please do not answer it for me, i only need help) I want to know how to do this next time.

Beastinonyou @ 8/11/2011, 9:15 pm wrote:
Just A Quick Note Regarding:

Step 2) Multiply the number by 2 to get a 5 digit number.


Have you considered what happens when a 4 digit number multiplied by 2 doesn't produce a 5 digit number?



Yes. It means the SIN is invalid, and the computer has completed its purpose early
Velocity




PostPosted: Wed Nov 09, 2011 3:20 pm   Post subject: RE:5+ bits the helper (please do not answer it for me, i only need help) I want to know how to do this next time.

Thanks for all your help guys Smile
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 2 of 2  [ 29 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: