Like Tree3Likes
  • 2 Post By Elkvis
  • 1 Post By Elkvis

Factorila Function !

This is a discussion on Factorila Function ! within the C++ Programming forums, part of the General Programming Boards category; Code: #include<iostream.h> #include<conio.h> void main() { clrscr(); int factorial=1; int N; cout<<"\nEnter Value For N as a Nonzero Integer :"; ...

  1. #1
    Registered User
    Join Date
    Nov 2013
    Posts
    4

    Red face Factorila Function !


    Code:
    #include<iostream.h>
    #include<conio.h>
    void main()
    {
        clrscr();
    int factorial=1;
    int N;
     cout<<"\nEnter Value For N as a Nonzero Integer :";
        cin>>N;
     {
    
     if(N==1||N==0)
     cout<<"\nFactorial is :"<<N;
    
      }
     while(N>1)
     {
     factorial=factorial*N;
     --N;
     }
       cout<<"\n\tFactorial is :"<<factorial;
        getch();
        }
    As i input 8 my sh**t compiler will print -ive values....Not before 7 to 2

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    2,499
    it looks like you're probably using turbo C++. this is a bad thing. the first thing I'd recommend is to get a real compiler like visual studio, code::blocks, or eclipse.

    your while loop should be in an else block after your if. as you have it, it will print the result twice if N is 0 or 1.

    edit: code::blocks and eclipse are actually IDEs, but code::blocks comes bundled with MinGW, or you can download MinGW separately and use it with eclipse.
    Last edited by Elkvis; 11-06-2013 at 09:20 AM.
    Elysia and Salem like this.
    Code:
    namespace life
    {
        const bool change = true;
    }

  3. #3
    Registered User
    Join Date
    Nov 2013
    Posts
    4
    Quote Originally Posted by Elkvis View Post
    it looks like you're probably using turbo C++. this is a bad thing. the first thing I'd recommend is to get a real compiler like visual studio, code::blocks, or eclipse.

    your while loop should be in an else block after your if. as you have it, it will print the result twice if N is 0 or 1.

    edit: code::blocks and eclipse are actually IDEs, but code::blocks comes bundled with MinGW, or you can download MinGW separately and use it with eclipse.
    Unfortunately our Professor Recommended this compiler.....And thankx for "else" , and i figured my problem i should use DOUBLE instead of int...but thankx for ur lil tym

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    2,499
    Quote Originally Posted by Xodix View Post
    Unfortunately our Professor Recommended this compiler
    you need to tell your professor that turbo C++ has been obsolete for 20 years, and that you're not being taught according to the current international C++ standard. your professor is dead wrong.

    Quote Originally Posted by Xodix View Post
    but thankx for ur lil tym
    most people on this forum prefer that you use proper english, and not shorthand. you'll likely find you get more help if you use complete sentences and words.
    Salem likes this.
    Code:
    namespace life
    {
        const bool change = true;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function Prototype, Function Call, and Function definition
    By dmcarpenter in forum C Programming
    Replies: 9
    Last Post: 04-09-2013, 03:29 AM
  2. Replies: 13
    Last Post: 03-20-2012, 08:29 AM
  3. Print function: sending a function.. through a function?
    By scarlet00014 in forum C Programming
    Replies: 3
    Last Post: 11-05-2008, 04:03 PM
  4. Replies: 14
    Last Post: 03-02-2008, 12:27 PM
  5. Replies: 9
    Last Post: 01-02-2007, 03:22 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21