roll a six-sided die until you get a six!

I need to assign rand(1,6) to a variable $roll and then continue the the loop on the condition $roll !=6 and echo $roll
All I did is :

<?php $rollC=0; $roll=rand(0,6); do{ if($roll!=6) { $rollC++; echo $rollC;} else {echo "achieved";} }while($roll!=6); { echo "achieved 6 on die";} ?>

Not able to make out where I am wrong?

You have an extra set of brackets for one, that should be causing an error.

And you only roll once. You could create a function that returns the random number that is called from the loop, or include the roll in the loop.

Well it will be really of help if you make the modifications in the code and put the right one here as a reply :slight_smile:

Or, you could try what I posted so you can show the teacher you did the assignment :smiley:

I would have if I could have. Anyway thanx .

It appears you are really putting forth the effort to succeed in school.

Yes if that is what defines a Beginner. :smiley: .Well ,yet the question remains unanswered.

You were told what to do. This site is not a code service for you to skate on homework. Beginner means new not lazy. Student means learning which you aren’t after if you want someone to do your work for you.

Locking this topic PM me if you can’t guess why.

Sponsor our Newsletter | Privacy Policy | Terms of Service