Home › Forums › C Programming › coin toss › Re: Re: coin toss
Small change:
/****************************************************************
* File Name : c:programshelppermutations.cpp
* Date : August,1,2002
* Comments : new project
* Compiler/Assembler :
*
*
*
*
*
* Program Shell Generated At: 5:59:12 p.m.
=-=-=-=-=-=-=-=–=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
#include < iostream >
//#include < string.h >
//#include < conio.h >
//#include < math.h >
//#include < iomanip >
//#include < ctype.h >
using namespace std;
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ FUNCTION PROTOTYPES @@@@@@@@@@@@@@@@@@@@@@@@@@
void coinPermutations ( int flips , char * permutations );
void coinPermutations ( char face , int flips , char * permutations );
//##################################################################################
//main function ******************************
int main ( )
{
int numberOfFlips;
cout << "enter number of flips: ";
cin >> numberOfFlips;
cout << "permutations: " << endl;
char * permutations = new char [ numberOfFlips + 1 ];
coinPermutations ( numberOfFlips , permutations );
delete [] permutations;
return 0 ;
}
/******************************* FUNCTION DEFINITION ******************************
Name : coinPermutatins
Parameters :
face a(n) char
Returns: Void type
Comments:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void coinPermutations ( int flips , char * permutations )
{
permutations [ flips ] = 0;
coinPermutations ( ‘h’ , flips – 1, permutations );
coinPermutations ( ‘t’ , flips – 1, permutations );
return;
}
/******************************* FUNCTION DEFINITION ******************************
Name : coinPermutatins
Parameters :
face a(n) char
Returns: Void type
Comments:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void coinPermutations ( char face , int flips , char * permutations )
{
if ( flips == 0 )
{
permutations [ flips ] = face;
cout << permutations << endl;
return;
}
permutations [ flips ] = face;
coinPermutations ( ‘t’ , flips – 1 , permutations ) ;
coinPermutations ( ‘h’ , flips – 1 , permutations );
return;
}