Recursion countdown

I need to write a program that when a user enters a number it counts down til blastoff. I need it to use recursion this is what I have so far

#include <stdio.h>
#include <iostream>
#include <stdlib.h>


using namespace std;

int main()
{

int SumTo(int time);
cin >> time;
if (time==0)
{
cout << "blast off" << endl ;
}
else
{
return SumTo(time - 1) + time;
cout << "you have << (time -1) + time << "seconds til blast off << endl;

}
return 0;
}

I can't seem to get it to work
I didn't test it, but this code looks more like a recursiv countdown:

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
27
28
29
30
31
#include <stdio.h>
#include <iostream>
#include <stdlib.h>

using namespace std;

int getCountdown(int);

int main()
{
  int time;
  cin >> time;		// read time
  getCountdown(time);   // start countdown
}

void getCountdown(int time)
{
  // if time = 0 explode
  if(time==0)			
  {
    cout << "blast off" << endl ;
  }
  else                  
  {
    cout << "you have" << (time) << "seconds til blast off" << endl;
    // wait a second, if not it would count faster than each second
    sleep(1);		
    // repead function with 1 second less	
    getCountdown(time-1);  
  }
}
Thank you very much! That helped a lot!
Topic archived. No new replies allowed.