I'm stuck with goto. I need to stop cause sometimes, it screws up my code. I used to do something like this.

int command;
start:
command = NULL; // this was a random guess to see if it would work
cin >> command;
if(command == 1){
cout << "Your chose 1" << endl;
pause; //I defined this
goto start;
}

And so after some heated debates over goto, I decided to try out the while. So now my code looks like this.

int command;
cin >> command;
        while(command == 1) 
               { 
                      reset; //resets command to null (this is defined)
     cout << "You chose 1" << endl;
               pause; //defined
  }

But when I run that, the code works other than the fact that it exits out after pause. How do I have it go back to the main "cin"?

lines 5 and 7 are do-nothing lines. The don't do a damned thing. You could delete both lines and the loop would work the same way.

>>//resets command to null
Says who???

Think about the flow.

How was the goto working?

Does the while loop take the flow the same way?

You need the flow to reach back to the cin.

For that you need to include the cin also in the loop.

>> But when I run that, the code works other than the fact that it exits out after pause. How do I have it go back to the main "cin"

int cmd = 0;
while( cin >> cmd) {
  if(cmdIsBad()) break; //out of the loop
  /* else logic goes here */
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.