Computer Science Canada 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. |
Author: | Velocity [ Tue Nov 08, 2011 6:46 pm ] | ||
Post subject: | 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. | ||
Pretty much they the assignment im working on is asking me to multiply the even numbers generated by 2 and then add them up to make one value. I am really stumped on how to do this. This is the code that i have written so far, dont mind the variables that i declared.
|
Author: | Velocity [ Tue Nov 08, 2011 6:48 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. |
in the second for statement When it says: step2 := ctr1 step2 := step2 * 2 put step2 I got confused, because i am unsure how to multiply the ctr1 numbers without hae a 2 come out in the outcome. |
Author: | Velocity [ Tue Nov 08, 2011 6:56 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. |
Bump! Still looking for help. |
Author: | Velocity [ Tue Nov 08, 2011 7:00 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. |
10 bits to helper! Fast please help. |
Author: | ProgrammingFun [ Tue Nov 08, 2011 7:09 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. |
Can you give the exact question? I don't understand what you're trying to do.. And stop multi-posting, it won't get anyone to respond faster... |
Author: | Velocity [ Tue Nov 08, 2011 7:27 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. |
6. Everyone has a nine digit Social Insurance Number (SIN) which is issued by the government. The government follows a certain method when issuing the SIN numbers so that they can check if they are valid or not. THe steps used to check that a SIN number is valid are as follows: 1) Create a four digit number by taking the digits in the even numbered positions. 2) multiply this number by 2 to create a five digit number 3) add the digits of this number together ( = evenSum) 4) add the digits in the odd numbered positions 1, 3, 5 & 7 (= oddSum) 5) take the units digit (ones digit) from the sum of evenSum and oddSum and subtract it from 10 6) the absolute value of the resulting number from the last step should equal to the value of digit 9 write a program that inputs a SIN number, cheecks to see if it is valid and outputs an apprpriate message. NOTE : The SIN number is 9 digit number << sorry for reposting, i didnt intend to get anyone to post faster, i was just trying to let people know that i am still here, and am still looking for help. |
Author: | Tony [ Tue Nov 08, 2011 7:40 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. |
So then, how far into the question are you? The posted code doesn't seem to be applicable to any of the steps. |
Author: | Velocity [ Tue Nov 08, 2011 7:49 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. |
That's the thing. I dont understand how to complete the question. I assumed that i was on step 2, but apparently not? |
Author: | Aange10 [ Tue Nov 08, 2011 7:52 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, 6:27 pm wrote: 6.
6) the absolute value of the resulting number from the last step should equal to the value of digit 9 Okay, so I assume you have completed all the steps up to 6. (Considering that is the number at the top of your response). So, you will need to have two things here. The resulting number of step 5 and the value of the 9th digit. Now, what does absolute value mean? http://en.wikipedia.org/wiki/Absolute_value Now that we know that, we can continue with the coding. So, the way a number in absolute value works is if the number is positive, then there is no change, where as if the number is negative, then the value is changed to positive (technically to no sign). Given that information, how would we implement that into coding? *TIP: ANumber > 0 is Positive, and ANumber < 0 is Negative. *SPOILER* Helpful code is posted below, if you'd like to see it, highlight it. -- Also, if it is another step you need help on, let me know. I figure you need help on this one because it is at the top of you're response. % Using Absolute Value if step_5_value >= 0 then elsif step_5_value < 0 then step_5_value := (step_5_value * -1) end if %Checking Number if step_5_value = digit_9 then put "Step_5_Value is equal to Digit_9!" else put "Step_5_Value is NOT equal to Digit_9!" end if |
Author: | Aange10 [ Tue Nov 08, 2011 7:53 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, 6:49 pm wrote: That's the thing. I dont understand how to complete the question.
I assumed that i was on step 2, but apparently not? Ahh, sorry. This post came after I replied before, but then I take it you are on step 2? |
Author: | Tony [ Tue Nov 08, 2011 7:56 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. |
Step 1. Given a 9 digit SIN, take the even digit positions to form a new number. That is: 123456789 => 2468 Do you have that done? |
Author: | Aange10 [ Tue Nov 08, 2011 8:07 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. |
Quote: 1) Create a four digit number by taking the digits in the even numbered positions. Okay so step one should be simple. Simply take the numbers from the nine digit code that are in an even spot. For this help session I'm going to use the code 123456789 as my Sin code. So we should declare our variables, SIN_digit_1, SIN_digit_2, digit_3 ... SIN_digit_9. (If you know Arrays, than do that as it would make things a lot easier). Now, what are the even positions of the nine digit code? 2,4,6, and 8 of course. For our example, it just so happens that our number for step 1 is 2468. I suggest you store this information as step_1 for later use. Quote: 2) multiply this number by 2 to create a five digit number Aha! Good thing we stored step_1 as a variable! Now, this should be simple. Take step_1 and multiply it by 2! I'd store the results as step_2_digit_1 .. step_2_digit_5 (etc.) for later use. **Note, it is obvious 123456789 is not a valid code. But we can still work using this example. Quote: 3) add the digits of this number together ( = evenSum) Great thing we saved each digit, huh? Now this is easy! Just add each digit of step 2. I'd store the results as step_3, and as evenSum (because the program tells you to. Later you could go back and remove step_3, but for now it is easy referencing.) Quote: 4) add the digits in the odd numbered positions 1, 3, 5 & 7 (= oddSum) Now, considering it says there are 7+ digits, I'll assume it's talking about the original SIN code. (Considering that in step 2 our outcome should have been 5 digits, not seven.) This should be easy as well, all we have to do is add SIN_digit_1, 3, 5, and 7! I'd save this as step_4 and as oddSum. Getting easier, right? Quote: 5) take the units digit (ones digit) from the sum of evenSum and oddSum and subtract it from 10 This should be super simple. All we have to do is add evenSum and oddSum and subtract it from 10. I'd save this as step_5. I've already explained step 6, and the messages should be simple to figure out now that you have the actual math done! However, if you still need help, feel free to ask! **ALSO if you know Arrays, it would be wise to store all this data in arrays. |
Author: | Velocity [ Tue Nov 08, 2011 8:12 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. |
@ Tony - Yes @ Aange im still reading your post. |
Author: | Aange10 [ Tue Nov 08, 2011 8: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. |
Also Velocity @ 8/11/2011, 6:00 pm wrote: 10 bits to helper! Fast please help.
Most of us do this for fun, because we enjoy helping others, and the general practice of programming. And Karma is nice (: |
Author: | Velocity [ 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. |
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?) |
Author: | Velocity [ 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. |
Author: | Aange10 [ 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
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. |
Author: | Velocity [ 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. |
Author: | Velocity [ 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. ![]() ![]() |
Author: | Velocity [ 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. ![]() |
Author: | Aange10 [ 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! |
Author: | Velocity [ 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? |
Author: | Aange10 [ 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. |
Author: | Velocity [ 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. |
Author: | Aange10 [ 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 |
Author: | Tony [ 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" |
Author: | Beastinonyou [ 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.
|
Author: | Aange10 [ 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 |
Author: | Velocity [ 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 ![]() |