How to limit a variable

Part of code I am using:

//person taking straws

cout << "\n\nHow many straws do you wish to take?";
cin >> straws_taken;
if (straws_taken>3)
{
cout << "\n Pay attention. I am pretty sure I said 3 or less."; //return to certain line

}
cout << "straws_taken:" << straws_taken;
straws=straws-straws_taken;
cout << "\nstraws remaining:" << straws; //displays amount of straws after user makes decision
if (straws<=1)


I am trying to make it so that the straws_taken variable which is something the player can control will allow the player to choose again after displaying "Pay attention. I am pretty sure I said 3 or less.".
I have gotten that sentence to display but the problem is that if I try to use a break or continue command the loop is exited and the program ends.
If C++ had a "goto" command I could just send it back to the line that says "cout << "\n\nHow many straws do you wish to take?", but to my knowledge it does not.

In short how do I allow a selection to be made, and limit straws_taken to no more than 3 straws.

PS:If this goes to the general forum I apologize in advance. I don't know how hard something had to be before it can no longer be in the beginner's forum.
Use the do...while syntax as below.
1
2
3
4
5
6
do {
cin >> n;
if (n > 3)
  cout << "3 or less! Try again!" << endl;
}
while (n > 3);
Thanks.

What should determine when I use "endl;" or when I just use ";"?
Topic archived. No new replies allowed.