Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > C++ Programming
|
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old April 17th, 2008, 07:32 PM
Registered User
 
Join Date: Apr 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default need help with permutation program

My program simply is suppose to calculate the permutation of the two given inputs.. however, I keep getting letters as my answer.. please, this is due tomorrow. can someone please help?





int factorial (unsigned long);
int permutation (unsigned long, unsigned long);
#include <iostream>
using namespace std;

int main()
{
    unsigned long n,r = 0;
cout << "please enter n value " << endl;
    cin >> n;
    cout << "please enter r value " << endl;
    cin >> r;
    cout << "P(" << n << "," << r << ") is equal to.." <<
    cout << permutation(n, r);


    return 0;
}

int factorial(unsigned long number) {
    int temp;

    if(number <= 1) return 1;

    temp = number * factorial(number - 1);
    return temp;
}

int permutation( unsigned long k, unsigned long r)
{
    int result = 0;
    int temp = k - r;

    result = factorial(k)/factorial(r);
    return temp;
}

Reply With Quote
  #2 (permalink)  
Old April 17th, 2008, 07:35 PM
Registered User
 
Join Date: Apr 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I can't find an edit button.. however...

last two lines are suppose to read

result = factorial(k)/factorial(temp);
    return result;


Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
Program to use for c# Doom C# 2005 2 January 4th, 2008 04:52 AM
need help! mean program xociology C++ Programming 3 March 19th, 2007 06:17 PM
anyone know of a program..... bammurdead C++ Programming 1 November 6th, 2005 08:16 PM
Setup Project: Program not added in Start>Program arif_1947 VS.NET 2002/2003 2 March 31st, 2005 06:40 AM
Start a program inside another program Silje Classic ASP Professional 1 November 16th, 2004 02:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.