
-----------------------------------
comp_help
Tue Nov 18, 2008 6:44 pm

turing - help w digit sensing
-----------------------------------
SAMPLE OUTPUT
Enter a number: 547
The last digit of 547 is seven

How would I do this TIPS question?? :? 
plz help :( 

Full Question:
Write a program fragment that prints, as a word, the value of the last digit of the int variable number. For example, if the value of number is 547, the fragment should print. HINT use the mod function to determine the last digit, then use the case statement to select the appropraite message.

-----------------------------------
andrew.
Tue Nov 18, 2008 6:53 pm

RE:turing - help w digit sensing
-----------------------------------
Sorry comp_help, but you have to attempt to do the program and post some kind of code. We don't give out homework answers here.

-----------------------------------
comp_help
Tue Nov 18, 2008 7:26 pm

Re: turing - help w digit sensing
-----------------------------------
SAMPLE OUTPUT
Enter a number: 547
The last digit of 547 is seven

How would I do this TIPS question?? :? 
plz help :( 

Full Question:
Write a program fragment that prints, as a word, the value of the last digit of the int variable number. For example, if the value of number is 547, the fragment should print. HINT use the mod function to determine the last digit, then use the case statement to select the appropraite message.

well i think i can divide odd number by 10, to find the last digit, but it only works with odd numbers. 


for example: 
51 div 10 = 5 
10 * 5 = 50 
51 - 50 = 1 

so the last digit is 1 

but i still need little help plz : :(

-----------------------------------
S_Grimm
Tue Nov 18, 2008 7:29 pm

RE:turing - help w digit sensing
-----------------------------------

var a : array 1..10 of char
for i : 1..10
get a(i)
end for


That will get you started i hope...

-----------------------------------
comp_help
Tue Nov 18, 2008 7:34 pm

Re: RE:turing - help w digit sensing
-----------------------------------

var a : array 1..10 of char
for i : 1..10
get a(i)
end for


That will get you started i hope...

im surry but i dont understand this stuff cuz i havent done this stuff yet, in my compsci class.  :? 

as it says in the question , solve by mod and case, tats wat i noe.

still need help  :(

-----------------------------------
comp_help
Tue Nov 18, 2008 7:59 pm

RE:turing - help w digit sensing
-----------------------------------
i have got it!

itz easy

var number: int
put "Enter a number:"

get number
number:= number mod 10

case number of
label 0: put "The last digit is ", number 
label 1: put "The last digit is ", number 
label 2: put "The last digit is ", number 
label 3: put "The last digit is ", number 
label 4: put "The last digit is ", number 
label 5: put "The last digit is ", number 
label 6: put "The last digit is ", number 
label 7: put "The last digit is ", number 
label 8: put "The last digit is ", number 
label 9: put "The last digit is ", number 
end case

-----------------------------------
Tony
Tue Nov 18, 2008 8:23 pm

RE:turing - help w digit sensing
-----------------------------------
could you explain how your case / label block works?

-----------------------------------
comp_help
Tue Nov 18, 2008 10:07 pm

Re: RE:turing - help w digit sensing
-----------------------------------
An explaination of the soution, if any1 needs it  :) 

ok, so basically the number is modded by 10. (mod is the remainder after the number is divided by 10)
the case is for the result that comes after the number is modded by 10.

for example:
letz pick an odd number: 99
99 mod 10 is 9
label 9: put "The last digit is ", number , so the last digit is then outputted by label 9.
The last digit is 9

letz pick an even number: 100
100 mod 10 is 0
label 0: put "The last digit is ", number , so the last digit is then outtputted by label 0.
The last digit is 0

hope this helps 8-)

-----------------------------------
The_Bean
Tue Nov 18, 2008 10:15 pm

Re: turing - help w digit sensing
-----------------------------------
The question asks you to output the last number as a word not an integer.
You can easily fix your case statement to do this.

-----------------------------------
comp_help
Tue Nov 18, 2008 10:30 pm

Re: turing - help w digit sensing
-----------------------------------
The question asks you to output the last number as a word not an integer.
You can easily fix your case statement to do this.

The_Bean u are right but as you said this can be easily fixed , so itz not a huge prob.  :wink:

-----------------------------------
Tony
Tue Nov 18, 2008 10:35 pm

Re: RE:turing - help w digit sensing
-----------------------------------
An explaination of the soution
What I was getting at, is that every case results in the same outcome, and every possible case is covered.

So why even have the case block?

get number

put "The last digit is ", number mod 10


-----------------------------------
andrew.
Wed Nov 19, 2008 6:28 pm

RE:turing - help w digit sensing
-----------------------------------
Instead of putting the numbers in the case block, make it actually say the number like:

label 0: put "The last digit is zero."
label 1: put "The last digit is one."
...
...
...
