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 257443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:05:50+00:00 2026-05-11T22:05:50+00:00

This program takes 2 numbers from user input, asks them whether they’d like to

  • 0

This program takes 2 numbers from user input, asks them whether they’d like to find out the permutations or combinations, and then outputs the result. Here’s the code.

#include "std_lib_facilities.h"

int permutation(int first, int second)
{
int top_fac;
int bottom_fac;
for (int i = first-1; i >= 1; --i)
    top_fac *=i;
for (int i2 = (first-second)-1; i2>=1; --i2)
    bottom_fac *= i2;
return (top_fac/bottom_fac);
}

int combination(int first, int second)
{
int bottom_fac;
for (int i = second-1; i>=1; --i)
    bottom_fac *= i;
return permutation(first, second)/(bottom_fac);
}

int main()
{
cout << "Enter two numbers.\n";
int first = 0;
int second = 0;
cin >> first >> second;
cout << "Now choose permutation(p) or combination(c).\n";
string choice;
cin >> choice;
if (choice == "p") 
   cout << "Number of permutations: " << permutation(first,second) << endl;
else if (choice == "c")
   cout << "Number of combinations: " << combination(first,second) << endl;
else
   cout << "p or c stupid.\n";
keep_window_open("q");
}

When I try to run the program, and I choose p or c, I get a “permutations_combinations.exe has stopped working” message. I tried to catch an error, but nothing is coming up. Any ideas?

Thanks in advance.

  • 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-05-11T22:05:50+00:00Added an answer on May 11, 2026 at 10:05 pm

    You’re not initializing the local variables top_fac and bottom_fac inside of your functions. Unlike other languages, local variables are NOT initialized to anything in particular in C or C++. The values that they receive are whatever garbage happens to be on the stack when you call the function. You should explicitly initialize top_fac and bottom_fac to 1 at the beginning of the permutation() and combination() functions.

    I’m guessing that bottom_fac is accidentally getting initialized to 0, and then you’re dividing by 0 at the end of the function, which is causing the runtime failure you’re seeing.

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

Sidebar

Ask A Question

Stats

  • Questions 209k
  • Answers 209k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer CLISP is just one implementation of Common Lisp. It's a… May 12, 2026 at 9:50 pm
  • Editorial Team
    Editorial Team added an answer I use nant scripts and psexec to execute them. Basically… May 12, 2026 at 9:50 pm
  • Editorial Team
    Editorial Team added an answer There are a number of ways to determine install/run locations… May 12, 2026 at 9:50 pm

Related Questions

This program takes 2 numbers from user input, asks them whether they'd like to
I am writing a program that takes in an input file from the user.
I am learning C and writing a simple program that will take 2 string
I have a table which is referenced by foreign keys on many other tables.
I've been tasked with taking an existing single threaded monte carlo simulation and optimising

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.