Computer Science Canada please help |
Author: | pokerface [ Wed Sep 29, 2004 8:24 pm ] |
Post subject: | please help |
hello, im making a program at school where we have to roll the die. i got as far as: ****************************************** var roll : int var first := 0 var die := 0 var die1, die2, die3, die4, die5, die6 := 0 var answer : string (1) loop put "Would you like to roll the die? " .. getch (answer) if answer = "y" or answer = "Y" then put "Yes" put "" put "" randint (die, 1, 6) case die of label 1 : put "You rolled a ", die die1 := die1 + 1 label 2 : put "You rolled a ", die die2 := die2 + 1 label 3 : put "You rolled a ", die die3 := die3 + 1 label 4 : put "You rolled a ", die die4 := die4 + 1 label 5 : put "You rolled a ", die die5 := die5 + 1 label 6 : put "You rolled a ", die die6 := die6 + 1 end case put "" elsif answer = "n" or answer = "N" then put "Exiting" exit delay (100) else put "" end if end loop ****************************** i want this program to be able to remember the first roll but continue rolling till the first roll is rolled again? then i want it to say how many rolls it took to get to the first roll! eg> (you rolled a 5 you rolled a 1 you rolled a 6 you rolled a 2 you rolled a 3 you rolled a 5 It took you 6 rolls) i understand that this question is pretty easy but im just learning turing now! so im REALLY new to turing! |
Author: | Andy [ Wed Sep 29, 2004 8:29 pm ] |
Post subject: | |
hmmm since ur new, i wont flame u, but nxt time plz dont put a topic thats more specific... and as for ur problem, just put the rolling part in a loop and have an if statement that exits the loop if the die number has a value of 1 |
Author: | pokerface [ Wed Sep 29, 2004 8:35 pm ] |
Post subject: | |
what do u mean put a if statement that exits the loop if the die number has a value of 1. i dont want it to exit i want it to count how many rolls it took before getting the first roll again. could u give me an example then? |
Author: | wtd [ Wed Sep 29, 2004 8:40 pm ] | ||||||||||
Post subject: | |||||||||||
If I may suggest one improvement... Use an array to keep track of how many times each side was rolled. Instead of:
Use:
Now:
Can become:
As for keeping track of the first roll... just start a counter outside the loop.
|
Author: | pokerface [ Wed Sep 29, 2004 8:46 pm ] |
Post subject: | |
i have to keep it in case construct! is there anything else that would do it while using case construct? |
Author: | wtd [ Wed Sep 29, 2004 8:49 pm ] |
Post subject: | |
pokerface wrote: i have to keep it in case construct! is there anything else that would do it while using case construct?
The first part of my post was independent of the second part. Your use of six different variables and the case statement will work, but it's way too much work. ![]() My suggestions for the counter and how to detect if the roll is the same as the first roll will still work. |
Author: | Dan [ Wed Sep 29, 2004 8:51 pm ] | ||||||||||
Post subject: | |||||||||||
[mod:bebab79606="hacker dan"] Dang, you all posted b4 me and b4 i saw u post anything. Oh well tho my awser is not bad even tho he whonts to case:? [/mod:bebab79606] Well 1st thing you should make more meaningfull subject titles for your posts. If you read the things that side read this befor asking for help you whould know not to say "i need help" or "pleas help" as the topic for the post. You are post in turing help so we know u need help ![]() Any how, you are not far off from what you have posted so far. You just need to sotre the 1st dice roll then comper all the others. now to do this we need to know if it is the 1st roll or not so i whould make a boolean var to be ture if it is the 1st roll and flase other wise:
Then we need to put some ifs in the area that runs when they enter y for whonting to roll agaen. the 1st if will check and see if it is the 1st time they rolled and if it is set the value of first to that roll and then set the value of firstRoll to false. If it is not the firstRoll we then need to check the value that was rolled and see if it was the same as the first roll:
now to make your code better u could get ride of all that case stuff and replace it with a simple:
b/c you do not need to keep track or how many rolls of each die but just how many rolls total. to do the total rolls you could simpley set roll to 0 to start with then add a line to add one to roll each time you roll after the 1st time, like so:
Also that dealy you have at the end will never be ran since u exit 1st, you may as well get ride of it. Affter all that your code will look somting like this:
And if you whont to make it even better you could probly get ride of the boolean var and check the value of roll insted but i think this way is easy to understand |
Author: | wtd [ Wed Sep 29, 2004 8:57 pm ] | ||||
Post subject: | |||||
In your example, the "roll += 1" should be outside the conditional. You'll want the number of rolls to be incremented by one even if it's the first roll. Also...
![]() |
Author: | Dan [ Wed Sep 29, 2004 9:04 pm ] | ||||
Post subject: | |||||
wtd wrote: In your example, the "roll += 1" should be outside the conditional. You'll want the number of rolls to be incremented by one even if it's the first roll.
Also...
![]() i thought he whonted it the other way? b/c how could u be trying to roll the 1st roll if u have not rolled it yet? |
Author: | pokerface [ Wed Sep 29, 2004 9:07 pm ] |
Post subject: | |
how would it work if its case thou? im understanding what u did but i dont want to show the teacher that i did something she hadnt though yet! eg true, false never learn't that ! sorry i just found out it dont have to be case, it could be an if statement but i still dont want to show her stuff that i never learned before! |
Author: | wtd [ Wed Sep 29, 2004 9:17 pm ] | ||
Post subject: | |||
The five minute version, with (I think) more clear variable names.
|
Author: | Dan [ Wed Sep 29, 2004 9:18 pm ] |
Post subject: | |
[mod:e4cdd87e1c="hacker dan"] Could i ever post 1st for once, grrrrr. dang you wtd and your fast posting!!!![/mod:e4cdd87e1c] pokerface wrote: how would it work if its case thou? im understanding what u did but i dont want to show the teacher that i did something she hadnt though yet!
eg true, false never learn't that ! sorry i just found out it dont have to be case, it could be an if statement but i still dont want to show her stuff that i never learned before! But if you do understand it from what we posted you have learned it ![]() Just tell her you did some resherch on your own. There is no reason to write bad code b/c the avg person in your class dose not know how to write good code :p Any how if u do not like the boolean stuff you could do what wtd side and put the roll += 1 out side and under the if and check to see if roll = 0 rather then checking the boolean var in my method. Then at the end if u whont the times that were rolled after the 1st dice witch is how i interpited the question you whould just take 1 away from roll. |
Author: | wtd [ Wed Sep 29, 2004 9:18 pm ] |
Post subject: | |
pokerface wrote: how would it work if its case thou?
Then show here that you understand it. That's great. However, using it here doesn't serve any purpose, and part of being a good programmer is knowing when not to use certain techniques. |
Author: | pokerface [ Wed Sep 29, 2004 9:29 pm ] |
Post subject: | |
ty guys/gurls (not sure ur gender) i learned alot. thanks for your time! |
Author: | rizzix [ Wed Sep 29, 2004 9:37 pm ] |
Post subject: | |
pfft we are all girls sheesh.. i thought it was quite obvious ![]() |
Author: | Andy [ Thu Sep 30, 2004 1:04 pm ] |
Post subject: | |
especially me, thats me on my avatar ![]() |
Author: | Mazer [ Thu Sep 30, 2004 2:39 pm ] |
Post subject: | |
*tee-hee* Yea, we're girls. Face it, computer science is a woman dominated field. |
Author: | the_short1 [ Thu Sep 30, 2004 6:30 pm ] |
Post subject: | |
WTD: so far i have seen u try to hhelp ppl in turing 3 times <today... just a suggestion.... tone it down a notch... u offer solutions of records..arrays... etc.... most of them dont know what thoes are / havnlt learn it yet... and if they go to their teacher wit hthat code.... well.. teachers are gona start givign those students shit for visiting compsci(thinking plagurism or something along those lines)... and / or posibly ban the website.... and ... pokerface and / others that are new.... theirs only about 5 girls in all of compsci.ca (that are known) well.. except Naoki... thats debatable... ![]() |
Author: | wtd [ Thu Sep 30, 2004 6:37 pm ] |
Post subject: | |
the_short1 wrote: WTD: so far i have seen u try to hhelp ppl in turing 3 times <today...
just a suggestion.... tone it down a notch... u offer solutions of records..arrays... etc.... most of them dont know what thoes are / havnlt learn it yet... and if they go to their teacher wit hthat code.... well.. teachers are gona start givign those students shit for visiting compsci(thinking plagurism or something along those lines)... and / or posibly ban the website.... I've specifically mentioned before that I don't feel giving people code will do them any good if they don't understand it. My own programming career has been fueled by learning things to improve my programming based on seeing the work of others that was more advanced than my own, not because someone set out a nice schedule for what I should learn and when. I bring that approach to any help I give. Yes, someone's going to get in trouble if they blatantly copy and paste code that they understand, but, if they do turn in code that's ahead of their class, and they understand it, then there's no harm, and there's great benefit because they've learned something new and eminently useful. So, no, don't cheat, but don't be afraid to tackle things your class hasn't covered yet. Just because your class hasn't covered them doesn't mean you can't understand them. |
Author: | pokerface [ Thu Sep 30, 2004 6:40 pm ] |
Post subject: | |
i told my teacher that i asked a friend for some help but she didnt really care! i just have one question, i want that program to finish when i press anything besides "Y" or "y"?? what could i do? please help. i didnt want to be "one gender sided" but ill just say guys from now on unless u want me to say something else? ![]() P.S i agree with WTD. if they understand it, then it just means he/she wants to learn and that is the point of school. Teachers enjoy seeing kids improve and learn without them having to do much work! ![]() ![]() |
Author: | wtd [ Thu Sep 30, 2004 6:52 pm ] | ||
Post subject: | |||
pokerface wrote: i told my teacher that i asked a friend for some help but she didnt really care! i just have one question, i want that program to finish when i press anything besides "Y" or "y"?? what could i do? please help.
Basically, if you're in a loop, you should be able to do something like:
|
Author: | Dan [ Thu Sep 30, 2004 8:02 pm ] |
Post subject: | |
wtd wrote: the_short1 wrote: WTD: so far i have seen u try to hhelp ppl in turing 3 times <today...
just a suggestion.... tone it down a notch... u offer solutions of records..arrays... etc.... most of them dont know what thoes are / havnlt learn it yet... and if they go to their teacher wit hthat code.... well.. teachers are gona start givign those students shit for visiting compsci(thinking plagurism or something along those lines)... and / or posibly ban the website.... I've specifically mentioned before that I don't feel giving people code will do them any good if they don't understand it. My own programming career has been fueled by learning things to improve my programming based on seeing the work of others that was more advanced than my own, not because someone set out a nice schedule for what I should learn and when. I bring that approach to any help I give. Yes, someone's going to get in trouble if they blatantly copy and paste code that they understand, but, if they do turn in code that's ahead of their class, and they understand it, then there's no harm, and there's great benefit because they've learned something new and eminently useful. So, no, don't cheat, but don't be afraid to tackle things your class hasn't covered yet. Just because your class hasn't covered them doesn't mean you can't understand them. I think the point is that if u start using things they have no idea about it is not realy helping them b/c they do not understand it and now have to go learn 10 other things to learn the 1st thing. True it is good to learn new ways of progaming and better ones but you can not go from nothing to uni level progaming, eplseyaly since this is turing made for poleop that have never progamed befor in there life. Most poleop taking thess corse are not going to be runing in to enums, recordes, class, ect for a awhile yet. Most schools do not get to OOP or recordes till grade 12 and turing is ushely only at grade 10. Now don't get me worng is it exteramly good that you are helping but i think it is making more work for both you and the person posting when u start off with an complex example. Just a sugestion whould be may be using a simpler example and then showing a complex one to show how they could improve there coding ablitys. Also posting exmaples in other progaming langues as exmaples in the turing help section is not a great help to poleop just starting to learn progaming. EDIT: i realy dont mean to be instating by any of this b/c you obsvley do have aot of knogale in thess areas just that the things is not every one asking for help dose ![]() |