0
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
   int a, result, factorial(a);
  {
   cout << "please enter a number ";
   cin >> a;
   cout << factorial(a);
  }

   
	for(a=1; a>0; a--)
	   {
		   factorial *=a;
       }
       return 0;
}
6
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by firstPerson
0

Just wondering if you felt like reading the intro threads, and HOW TO POST CODE anytime whilst waiting for an answer.

0

Code isn't make much sense either. You define factorial as a function but then you multiply 1 and 0 to it like a variable!

And Please help doesn't state the problem. Your code is obviously flawed but we really don't know what the problem you are having is, and exactly what your assignement was!

0

He already stated his question, "please can any1 help fix this...... ", and I think it's fair we answer it... Yes we can fix this. Hope I was able to help you, xfreebornx. :P

-1

factorial function:

in factorial(int x) {
int t;

for(t = x; t >-;t++)
     x = x*t;

return x;
}

I hope you read into function calling and creation.

Votes + Comments
1. Wrong approach to help - do not throws code. 2. Source code in post #5 - is it compiled & executed?
-1

Lets see what you are doing :

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    int a, result, factorial(a);  //declare 'a' as an int
                                            //declare 'result 'as an int
                                           //declare 'factorial' as in int, initialized to
                                           //the value of 'a' which is ? junk...
{
cout << "please enter a number ";  //ask user for input
cin >> a; //read in the input
cout << factorial(a);    //display factorial(a) ??? I assume you believe
                                   //that factorial is defined in cmath, which is                                                
                                  //not, and if you do then why were you declaring it as a variable?
}


for(a=1; a>0; a--) //start a loop from a = 1 until a <=0, which means
                            //this loop will only execute once 
 {
   factorial *=a;  //now take the variable functions thingy and
                          //multiply it by a, which is 1 , which means the
                         //variable function thingy has not changed
  }
return 0; //return success, as if it were.
}
Votes + Comments
No need to this post - See OP's post #1. He/She has missed code tags.
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.