Hi i'm currently trying to do a recursion homework assignment that does the factorial of any number the user inputs. I'm having trouble with getting the number the user inputs, and putting it in the function. Any suggestions?
#include <iostream>
using namespace std;
int fact(int n);
int main()
{
char ch;
int choice;
do
{
cout << "Pick any positive integer: " << fact(choice);
cin >> choice;
cout << "Press 'y' to run again, any other key to quit:";
cin.ignore();
cin.get(ch);
} while (ch =='y' || ch =='Y');
return 0;
}
int fact(int n)
{
int answer;
if (n==1)
return 1;
else
answer = fact(n-1) * n;
return answer;
}
this is what i have so far. and it says i have an "uninitiali zed local variable 'choice' used" in the bolded area.
#include <iostream>
using namespace std;
int fact(int n);
int main()
{
char ch;
int choice;
do
{
cout << "Pick any positive integer: " << fact(choice);
cin >> choice;
cout << "Press 'y' to run again, any other key to quit:";
cin.ignore();
cin.get(ch);
} while (ch =='y' || ch =='Y');
return 0;
}
int fact(int n)
{
int answer;
if (n==1)
return 1;
else
answer = fact(n-1) * n;
return answer;
}
this is what i have so far. and it says i have an "uninitiali zed local variable 'choice' used" in the bolded area.
Comment