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

Username:   Password: 
 RegisterRegister   
 turing - help w digit sensing
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
comp_help




PostPosted: Tue Nov 18, 2008 6:44 pm   Post subject: 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?? Confused
plz help Sad

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.
Sponsor
Sponsor
Sponsor
sponsor
andrew.




PostPosted: Tue Nov 18, 2008 6:53 pm   Post subject: 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




PostPosted: Tue Nov 18, 2008 7:26 pm   Post subject: Re: turing - help w digit sensing

comp_help @ Tue 18 Nov, 2008 6:44 pm wrote:
SAMPLE OUTPUT
Enter a number: 547
The last digit of 547 is seven

How would I do this TIPS question?? Confused
plz help Sad

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 : Sad
S_Grimm




PostPosted: Tue Nov 18, 2008 7:29 pm   Post subject: RE:turing - help w digit sensing

code:

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




PostPosted: Tue Nov 18, 2008 7:34 pm   Post subject: Re: RE:turing - help w digit sensing

A\V @ Tue 18 Nov, 2008 7:29 pm wrote:
code:

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. Confused

as it says in the question , solve by mod and case, tats wat i noe.

still need help Sad
comp_help




PostPosted: Tue Nov 18, 2008 7:59 pm   Post subject: 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




PostPosted: Tue Nov 18, 2008 8:23 pm   Post subject: RE:turing - help w digit sensing

could you explain how your case / label block works?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
comp_help




PostPosted: Tue Nov 18, 2008 10:07 pm   Post subject: Re: RE:turing - help w digit sensing

An explaination of the soution, if any1 needs it Smile

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 Cool
Sponsor
Sponsor
Sponsor
sponsor
The_Bean




PostPosted: Tue Nov 18, 2008 10:15 pm   Post subject: 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




PostPosted: Tue Nov 18, 2008 10:30 pm   Post subject: Re: turing - help w digit sensing

The_Bean @ Tue 18 Nov, 2008 10:15 pm wrote:
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




PostPosted: Tue Nov 18, 2008 10:35 pm   Post subject: Re: RE:turing - help w digit sensing

comp_help @ Tue Nov 18, 2008 10:07 pm wrote:
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?
Turing:

get number

put "The last digit is ", number mod 10
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
andrew.




PostPosted: Wed Nov 19, 2008 6:28 pm   Post subject: RE:turing - help w digit sensing

Instead of putting the numbers in the case block, make it actually say the number like:

code:
label 0: put "The last digit is zero."
label 1: put "The last digit is one."
...
...
...
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 1 of 1  [ 12 Posts ]
Jump to:   


Style:  
Search: