new to c++. plz help me in this...

i am new to c++. plz help me, i have to submit my program tomorrow.

#include
#include
void main()
{
factorial();
getch();
}
factorial()
{
int i,n,fact=1;
clrscr();
cout<<"Enter The Number To Find Factorial: ";
cin>>n;
i=1;
while(i<=n)
{
fact=fact*i;
i++;
}
cout<<"
The Factorial = "<<fact;
}

I am getting error "function factorial should have a prototype
i am getting warning function should return a value.

Comments

  • : i am new to c++. plz help me, i have to submit my program tomorrow.

    [color=Red]First off formatted code for the win:[/color]

    : [code]
    : #include
    : #include
    :
    : void main()
    : {
    : factorial();
    : getch();
    : }
    :
    : factorial()
    : {
    : int i, n, fact = 1;
    : clrscr();
    : cout << "Enter The Number To Find Factorial: ";
    : cin >> n;
    : i = 1;
    : while( i <= n )
    : {
    : fact = fact * i;
    : i++;
    : }
    : cout << "
    The Factorial = " << fact;
    : }
    : [/code]
    :
    : I am getting error "function factorial should have a prototype

    [color=Red]Makes sense considering you call factorial before you ever declare it.[/color]

    : i am getting warning function should return a value.

    [color=Red]C defaults function return types to [color=Blue]int[/color] if you do not explicitly give one like in this case.

    That's all I'm going to say, you'll need to figure out how to fix it on your own considering this is your assignment. And I am fairly certain that the teacher would have covered all the material that you would need to complete it.
    [/color]

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion