Here's another way to do it:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string age;
cout<<"Hello!"<<endl;
do
{
cout<<"How old are you? (Type 0 to quit): ";
getline(cin, age);
cout<<""<< age <<"?! I doubt that!"<<endl;
} while( age[0] != '0' );
return 0;
}
'do...while' will always display your prompt at least once, and is more natural in this case. The condition is tested at the end of the loop, instead of the start.
Also note that the test condition was based on the value of the first character of the string, 'age[0]'. The escape character in this case is '0', as indicated in the prompt. If you do it this way, you don't need to create a new variable like 'exitchoice'. Personally, I like prompting the user if they want to continue, like twitch did, but I thought I'd show you an alternative. Either one may be more natural based on your programming needs. Here's the code for the alternative construction:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string age;
string exitchoice;
cout<<"Hello!"<<endl;
do
{
cout<<"How old are you?: ";
getline(cin, age);
cout<<""<< age <<"?! I doubt that!"<<endl;
cout<<"Would you like to try again? [y/n]: ";
getline(cin, exitchoice);
} while( exitchoice[0] != 'n' );
return 0;
}
In this case, if the user types anything but 'n', the loop will continue. Of course, there are lots of other ways of doing this, but hopefully this should give you some ideas.
As far as 'goto' goes, it is still a valid keyword, but it should be avoided in most cases. Code clarity should always be your top priority. Most of the time, goto makes things messy, so it's counterproductive to use it. If you happen to be deeply nested in several loops and conditional statements and you encounter an error and need to exit quickly and cleanly, it would probably be
more clear to use goto than a series of 'break' statements. When writing code, always keep this mantra in mind: "What is the clearest way I can express this instruction?"