-
April 25th, 2004, 01:11 AM
#11
So what, since I don't know C++, you won't say hi to me???
Insensitive *****
-
April 25th, 2004, 03:19 AM
#12
Factorial Prog in C++
Code:
/*Find the factorial of a given number -(as far as unsigned long int(s) go)-
By: AxessTerminated
P.S. This program is a nice example of recursive functions
*/
#include <iostream.h>
unsigned long x;
unsigned long my_fact(unsigned long x);
main(){
cout << "Find factorial of..\n";
cin >> x;
cout << "Factorial of " << x << " is\n";
cout << my_fact(x) << endl;
system("pause");
return 0;
}
unsigned long my_fact(unsigned long x)
{
if (x <= 1 )
return 1;
else
return x * my_fact(x - 1);
}
Geek isn't just a four-letter word; it's a six-figure income.
-
April 25th, 2004, 03:27 AM
#13
Once again, another app by God, Himself
j/p, im still rather new to the language, just figured I could post some things...
:::::::::::::::::::::::::::::::::::::::::::::
Code:
/*Probability Simulator 1.7
by: AxessTerminated
Version History
Version Description/Changes
---------------------------------------------
v.0.9 Die Roller
v.1.2 Added primitive coin flipping
v.1.5 Added Random Number Generation
v.1.5.1 Added The Quit Option ;)
v.1.5.2 Added Version History
v.1.7 Program restarts instead of exiting--"goto start;" at end of main()
*/
#include <iostream.h>
int fdice();//For dice rolling.
int fcoins();//For coin flipping.
int frand();//For the random number generator.
int gen;//Amount of generations.
int range;//the variable that specifies 0-x, or 1-x (e.g. 1-6 for 6 sided dice).
int x;//In the for() loop to simulate multiple generations.
int zero_inc;//variable to define the inclusion of zero (0-x or 1-x)
int choice;
main()
{
start:
system("cls");
cout << "1. Coins\n2. Dice\n3. Random Number Generator\n4. Quit\n:";
cin >> choice;
switch(choice)
{
case 1:
fcoins();
break;
case 2:
fdice();
break;
case 3:
frand();
break;
case 4:
return 0;
default:
goto start;
}
goto start;
}
//Roll Dice
int fdice()
{
system("cls");
cout << "How many dice?\n:";//How many generations of rand() do you want?
cin >> gen;
cout << "How many sides on the dice?\n:";
cin >> range;
srand(time(0));
system("cls");
for(x=1; x <= gen; x++)
{
cout << "Roll #" << x << ": " << rand() % range+1 << endl;
}
system("pause");
}
//Flip Coins
int fcoins()
{
system("cls");
cout << "How many coins?\n:";//How many generations of rand() do you want?
cin >> gen;
range = 2;
srand(time(0));
system("cls");
for(x=1; x <= gen; x++)
{
cout << "Flip #" << x << ": " << rand() % range+1 << endl;
}
system("pause");
}
int frand()
{
system("cls");
cout << "How many numbers?\n:";//How many generations of rand() do you want?
cin >> gen;
cout << "Include 0? 0=Yes, 1=No\n:";
cin >> zero_inc;
cout << "Maximum Number?\n:";
cin >> range;
srand(time(0));
system("cls");
for(x=1; x <= gen; x++)
{
cout << "Integer #" << x << ": " << rand() % range+zero_inc << endl;
}
system("pause");
}
I have a site: www.angelfire.com/linux/axessterminated
there is a a C++ page on there (link on the left) also a link to a friends site:
http://lexclient.cjb.net
That's phil, he's pretty damn good with C++, check it out.
Also, do you program yourself, or are you looking to learn?
Geek isn't just a four-letter word; it's a six-figure income.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|