Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9173155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:31:23+00:00 2026-06-17T16:31:23+00:00

Half an hour ago, I made a simple factorial calculator that takes non-zero integers

  • 0

Half an hour ago, I made a simple factorial calculator that takes non-zero integers as inputs. After testing it for some values, I noticed that it only work properly until 12!.

I haven’t been programming for some months now, and still am a beginner to be honest. I decided to use recursion so I could get back in to “programming mode” faster (my preference).

I checked and modified it for almost an hour now. I don’t really know what is wrong with my algorithm.

This is my code:

#include <iostream>

using namespace std;

int factorial(int);

int main()
{
    int usrInput = 0;   //initialize input variable
    cout << "Please input the factorial you want to calculate: ";
    cin >> usrInput;
    while(usrInput < 1)
    {
        cout << "Please input a valid number: ";
        cin >> usrInput;
    } //end while
    cout << "\nAnswer: " << factorial(usrInput) << '\n';
    return 0;
}

int factorial(int n)
{
    int product = n;
    if(n < 2)
        product = 1;
    else
    {
        product *= factorial(n-1);
    cout << "\n" << product; //debugging line
    } //end if else
    return product;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:31:25+00:00Added an answer on June 17, 2026 at 4:31 pm

    You exceed limits of int. 13! = 6227020800, int only covers -2147483648 .. 2147483647. Use bigger type (eg. __int64), double (but you’ll lose precision) or implement (or use) big number library.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Purpose : Every half-hour I query database to find a post that havn't published
A former colleague of mine started a discussion half an hour ago about JavaBeans,
My body background is not showing. It was working fine half an hour ago,
I'm totally new to Python (as of half an hour ago) and trying to
I have two alarms that fire two separate services--one is executed every half-hour, and
I just spent a half hour debugging some new code that's not broken because
I have a small script that launches and, every half hour, feeds a command
I am running Ubuntu 9.04 and have done about a half hour worth of
I've been reading about this for the last half hour, and here's what I
I'm fighting with this already 1 and a half hour, but can't find a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.