Void funtion recursive

¡Hi!
I have to do a recursive void function that do the same thing as this program.

#include <iostream>
using namespace std;

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main() {

int num;
cout << "Write a number: " << endl;
cin >> num ;
for ( int i=0; i<num; ++i ) {
cout << "*" << endl;
}


return 0;
}
Thanks (:
Last edited on
Hope this helps! :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <map>
#include <random>
#include <ctime>

using namespace std;

void asterisks(int i){
    if(i>0){
        cout<<"*"<<endl;
        asterisks(i-1);
    }
}

int main()
{
    int num;
    cout<<"Give me a positive number: "<<endl;
    cin>>num;
    asterisks(num);



    return 0;
}
I lost a lot of time trying to figure out how to do that, because I don't understand pretty well the recursion.
So, thank you so much! (:
Topic archived. No new replies allowed.