How do i fix error?? Error: expected ";" before "factorial"? it says in Line 16
I'm getting an error and do not know how to fix it. My code is as follows:
#include <iostream>
using namespace std;
int main(){
int factorial = 1, current = 2, n;
cout << "enter number to calculate factorial of: ";
cin >> n;
while (current <= n){
factorial = current * factorial;
current++;
}
cout << n << "!= " factorial << endl;
while (n < 0) {
cout << "Must enter a positive number!\n";
cout << "re-Enter 开发者_Go百科number to calculate factorial of: ";
cin >> n;
}
return 0;
}
You're missing an operator:
cout << n << "!= " factorial << endl;
Should be:
cout << n << "!= " << factorial << endl;
精彩评论