PDA

View Full Version : Quick question about C functions


DoubtlessOne
10-24-2005, 04:13 AM
Anybody know how to do a code snippet which allows the program to go back to it's previous menu?

i.e.

int main()
{
blah blah codes here;
cin>>x;

if(x==1)
{
such and such codes here;
}
}

what I basically want to do is.... from the "if" statement I want to go back to "int main"
anybody got a clue?
now what I want to do is...

shmoove
10-24-2005, 05:53 PM
There are plenty of ways of achieving that kind of behaviour. The most obvious would be to just call main:

if (something) {
main()
}

But that would be a very bad way in this case.

I'd say what you need here is a while loop around all the part that needs repeating. Something along the lines of:

int main()
{
int x;
do {
blah blah codes here;
cin>>x;
}
while (x == 1);
}


The next step will probably be to organize your code into functions that take care of the different parts and call those from main, but that's for another day ;)

shmoove