Hi everyone! I started learning about c++ on my own, but at each step have a lot of problems...if someone could help me, I would be soo grateful. I tried to find out what`s wrong, but can`t find an answer.
so...
#include <iostream>
using namespace std;
int main() {
int i, n, fac = 1;
cout << "Enter a positive integer";
cin >> n;
for (i = n; i>1; i--) {
fac = fac * i;
cout << "Factorial is: " << fac << endl;
}
return 0;
}
Within the limits of int capacity the program runs perfectly. Except maybe swap the last cout line and the following } line so that only the result is displayed.
#include <iostream>
usingnamespace std;
int main() {
int i, n, fac = 1;
cout << "Enter a positive integer ";
cin >> n;
for (i = n; i>1; i--)
{
fac = fac * i;
}
cout << "Factorial is: " << fac << endl;
return 0;
}
Enter a positive integer 7
Factorial is: 5040
Runs here perfectly including with the swap I mentioned. :)
I just copied this, and now it works! I don`t know why it doesn`t work when I type it by myself.... thank you, this little stupid thing took me a couple of days.
:)