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

Username:   Password: 
 RegisterRegister   
 how to add a counter and a add 7 for this problem?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
batman12




PostPosted: Wed Jan 11, 2006 5:37 pm   Post subject: how to add a counter and a add 7 for this problem?

hey,
i'm back. hi i am back. hi i just created this solution but i don't know how to add a counter to count how manny numbers are divisible and how to add the nummber seven and do the same thing as 3 in the same problem?thanks. any help is aprreciated.thanks
code:
for count :1..1000 
    if   (count mod 3=0 ) then %i need to put number 7 here so it can do the same thing as three
    put " The number " ,  count ,  " is divisible by three "
    end if
   
end for
put "There are 333 numbers divisible by three from 1 to 100."  %i need help putting a counting that counts this for me without me counting it.

thnaks.
Sponsor
Sponsor
Sponsor
sponsor
chrispminis




PostPosted: Wed Jan 11, 2006 5:47 pm   Post subject: (No subject)

Well, to do it by 7's you could use remainders, although theres probably a better way. Then just add new variable and add to it when you find a number divisible by 7.
code:

if count rem 7 = 0 then
put " The number is currently divisible by seven"
countSevens := countSevens + 1 % You can also use countSevens += 1
end if


hope that helps
Tony




PostPosted: Thu Jan 12, 2006 3:31 pm   Post subject: (No subject)

you could have incremental for loops
code:

for i: 1 .. 100 by 7
    ...
end for

I think that's the syntax
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Geminias




PostPosted: Fri Jan 13, 2006 5:42 am   Post subject: (No subject)

Quote:

for count : 1..1000
if (count mod 3 = 0 ) then %i need to put number 7 here so it can do the same thing as three
put " The number " , count , " is divisible by three "
else if (count mod 7 = 0) then
put " The number ", count, " is divisible by seven."
end if

end for
put "There are 333 numbers divisible by three from 1 to 100." %i need help putting a counting that counts this for me without me counting it.



if this is what you are talking about.. then this is how you do it lol. unless you have to check that they are either divisible by seven or three then you can just add "and" between the comparision statements.
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  [ 4 Posts ]
Jump to:   


Style:  
Search: