Help plz

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

  • Looking at what you've got, to fix the prototype, add
    [code]
    // bits of code

    void factorial();

    int main() {

    // bits of code
    }

    void factorial() {

    // bits of code
    }[/code]

    For the other, in C++ main returns an int

    [code]
    #include

    int main() {

    std::cout << "hello world" << std::endl;
    return 0;
    }[/code]


  • Fun fact. in C++ the minimal program is:
    [code]
    int main( void ) { }
    [/code]

    It's a language specification that main is the only function with a return value that doesn't in-fact need to return anything. Implementations are required to interpret no return from main as returning success to the invoking system.
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