|
-
Aug 21st, 2001, 03:53 PM
#1
Thread Starter
Member
Functions(basic)
I have a problem with this simple program(well...not so simple for me).
Could someone help me out and tell me what mistakes i made please...
Here it is:
#include <iostream.h>
#include <stdlib.h>
#include <random.h>
void result (&usersum, &compsum)
{
if (usersum < 21 && compsum < 21)
{
cout << "we draw";
int draws(&draw)
{
draw = draw + 1;
return draw;
}
else if (usersum > compsum && usersum < 21)
userwin = userwin + 1;
int uwins(&uwin)
{
uwin = uwin + 1;
return uwin;
}
else
cout << "I win";
int cwins(&cwin)
{
cwin = cwin + 1)
return cwin;
}
}
}
int main()
{
int numberofcards;
int cwin = 0, uwin = 0; draw = 0;
int usersum = 0, compsum = 0;
char destination;
do
{
randomize();
cout << "How many cards do you want? \n";
cin >> numberofcards;
void userrandom(&usersum, numberofcards, int rnd)
{
for (int number = 1; numberofcards < number; number++)
{
int max = 10;
rnd = 1 + random(max);
usum(&usersum, &rnd)
{
usersum = usersum + rnd;
return usersum;
}
cout << "You: " << rnd;
}
}
void comprandom(&compsum, int rnd1)
{
for (int compnum = 1; comnum < 3; compnum++)
{
int maxnum = 10;
rnd1 = 1 + random(maxnum);
int csum(&compsum, *rnd1)
{
compsum = compsum + rnd1;
return compsum;
}
cout << "computer: " << rnd1;
}
}
cout << "I have " << csum() << "and you have " << usum << "so "
<< result(&usersum, &compsum) << ".\n";
cout << "Would you like to play again? (Y/N)?\n";
cin >> destination;
}
while (destination == Y)
cout << "Computer wins: " << cwins(&cwin) << endl;
cout << "Your wins: " << uwins(&uwin) << endl;
cout << "Draws: " << draws(&draw) << endl;
system("PAUSE");
return 0;
}
PS. I use the Dev- C++ compiler, and when i put the liblary <random.h> it doesnt exist. Does anybody know where the random number library might be?
-
Aug 21st, 2001, 04:04 PM
#2
As far as i know, there is no "Random()" function. To use random numbers, #include <stdlib.h>, and call "rand()" It takes no parameters, and returns a number from 0 to MAXINT. To get numbers within a certain range, say, 0-10, call "(rand() % 11)".
Z.
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
|
Click Here to Expand Forum to Full Width
|