can you call a function inside that same function so that it goes to the beginning of that code to execute it. So even though ur already in the prompt function can u still call it again from withing the code inside the prompt function. Thanks in advance.

Re: calling a function inside that same function 80 80

Yes, you can, it is called recursion. Look it up on net

Re: calling a function inside that same function 80 80

>can you call a function inside that same function
If I understood that correctly then..

If you call a function while your already in it, you have recursion. Take this as an example.

#include <iostream>
using namespace std;

void CountDown(int number) {
   if (number != 0) {
      cout << number << '\n';
      CountDown(--number);
   }
}

int main() {
   CountDown(100);
   cin.ignore();
   return 0;
}

This will keep calling the CountDown function, subtracting 1 from that number, and then displaying it until number reaches 0, when that happends, it will stop calling CountDown and it will break out the loop. Here is a tutorial on recursion - http://www.cprogramming.com/tutorial/lesson16.html

Hope this is what your looking for ;)

Re: calling a function inside that same function 80 80

Of course, you can do that. It's called recursion. The only problem is to break recursive call chain in the proper moment. In other words you must prevent f() call which calling f() which calling f() again and so on...

Re: calling a function inside that same function 80 80

ok thanks for ur help

Re: calling a function inside that same function 80 80

3 answers at pretty much the same time ^.^ thats a record for me.

Re: calling a function inside that same function 80 80

how to call a function twice in the same method ??

Be a part of the DaniWeb community

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