Hi folks! Was wondering if you could help with a problem. I'm supposed to write a function that writes n, n-1, n-2, …, 3, 2, 1. I'm pretty sure I've got it but for some reason I keep getting 0 whenever I run it. It doesn't have to be a recursive function but I've been writing it that way. Any help would be awesome. Thanks!
#include <iostream>
using namespace std;
int backwards (int);
void main ()
{
int key;
cout << "Enter a positive integer : ";
cin >> key;
cout << backwards(key) << endl;
}
int backwards (int n)
{
if (n==0)
return 0;
else
for (n=1; n>0; n++)
return (n-1);
}