Results 1 to 3 of 3

Thread: [RESOLVED] error

  1. #1

    Thread Starter
    Fanatic Member vivek_master146's Avatar
    Join Date
    Apr 2006
    Location
    Delhi,India
    Posts
    787

    Resolved [RESOLVED] error

    #include <iostream.h>
    #include <conio.h>
    int main ()
    {
    int i,num,fact=1;
    cout<<"\nenter interger:";
    cin>>num;
    i = num;
    while(num);
    {
    fact *=num;
    --num;
    }
    cout<<"the factorial of"<<i
    <<"is"<<fact<<"\n";

    return 0;
    ------------------------------------
    this code return the factor of the integer entered. Why it is not working properly when i am entering a integer.

  2. #2
    Fanatic Member twanvl's Avatar
    Join Date
    Dec 2001
    Posts
    771

    Re: error

    In what way is your code "not working properly"? Do you get an error when you compile it? Does it crash? Do you get the wrong answer?

    Also, for readability, please put your code between [code][/code] tags.

  3. #3
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: error

    that's because you have placed a semi-colon ; after the While statement
    Code:
    #include <iostream.h>
    #include <conio.h>
    int main ()
    {
    int i,num,fact=1;
    cout<<"\nenter interger:";
    cin>>num;
    i = num;
    while(num);<-- remove this semi-colon
    {
    fact *=num;
    --num;
    }
    cout<<"the factorial of"<<i
    <<"is"<<fact<<"\n";
    
    return 0;
    }
    Show Appreciation. Rate Posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width