#include<iostream>
// Unless system("cls"); uses these header files, they should be removed.
//#include<stdio.h>
//#include<stdlib.h>
usingnamespace std;
int factorial(int, int);
int main()
{
system("cls");
int x=1, n;
char ch;
do {
cout << "enter no.: ";
cin >> n;
x = factorial(x, n);
cout << x << endl;
cout << "Again? (y/n): ";
cin >> ch;
cout << "\n\n"; // this is same as endl x 2
} while (ch == 'y');
cout << "ended\n\n";
return 0;
}
int factorial(int a, int b)
{
while (b != 1)
{
a = a*b;
b--;
}
return a;
}
system("cls"); doesn't work for me, so I left it where it is. If it works for you, then move it down to line 17 to get the result you're looking for.
Seems a typical problem with a dangling '\n'
cin >> n; will not remove the '\n' so getchar() will read it into ch and while (ch == 'y'); will be false.