int x, factorial = 1;
cout << "Enter integer: ";
cin >> x;
if (x > 0)
{
while (x > 0)
{
factorial *= x;
x--;
}
}
cout << "Factorial: " << factorial;
Untested, this might work.
cscgal
The Queen of DaniWeb
19,422 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 230
What output does it give?
Try int x;
int factorial=1; on two separate lines?
cscgal
The Queen of DaniWeb
19,422 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 230
Oops! Just realized
the last line should cout << factorial
not cout << x
edited post above to fix error
cscgal
The Queen of DaniWeb
19,422 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 230
Make sure your whole program is enclosed in
#include<iostream.h>
int main()
{
[ CODE GOES HERE ]
return (0);
}
cscgal
The Queen of DaniWeb
19,422 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 230
You're missing a } to end the if statement.
cscgal
The Queen of DaniWeb
19,422 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 230
Pardon me, Bob, but don't you think a pm on that would have been more appropriate?
aeinstein
Team Member - aka kaynine
645 posts since May 2002
Reputation Points: 186
Solved Threads: 8
Pardon me, aeinstein, but don't you think a pm on that would have been more appropriate? ;)
I'm just joking. Ok now someone say it back to me. :)
samaru
a.k.a inscissor
1,256 posts since Feb 2002
Reputation Points: 262
Solved Threads: 18
that was my point *exactly*!!!
aeinstein
Team Member - aka kaynine
645 posts since May 2002
Reputation Points: 186
Solved Threads: 8
well bob its a required course so if i make it through you'll never hear from me again until then i need some help and answers
LOL! OK, with an attitude like that, just what CENTURY do you think it's going to be before Bob helps you with an assignment again? ROFLOL! :D
aeinstein
Team Member - aka kaynine
645 posts since May 2002
Reputation Points: 186
Solved Threads: 8
Look's like I stand corrected - pleasantly surprised you to took the time to make another reply Bob.
aeinstein
Team Member - aka kaynine
645 posts since May 2002
Reputation Points: 186
Solved Threads: 8
he ha ha ha ha ha ah aha aha aha aha haa ha ha ha ha ha ha aha ha aha ahja aha ha ah 11 :rolleyes: :p :lol: :mad: :( :mrgreen:
Please refrain from bumping two year old threads.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401