![]() |
|
#1
|
|||
|
|||
Help with Dice programCPP / C++ / C Code:
I cant see whats wrong with it. I want RAND_MAX to equal 6. Even though i've defined it it still wont work. All I want is to play a game i used to play in Dice. Each player rolls 4 times the one closest to 21 wins |
|
#2
|
|||
|
|||
Re: Help with Dice programQuote:
RAND_MAX is defined in the standard library header <stdlib.h> All calls to the function rand() will return values from 0 to RAND_MAX (inclusive) as defined by the compiler's distribution library. You can't change the library function's action by trying to define your own value of RAND_MAX. Consider this: CPP / C++ / C Code:
If you want a number from 1 to 6 (inclusive), then you can try this: CPP / C++ / C Code:
Regards, Dave Using the modulus operator, %, for positive integers x and n, in an expression like this: CPP / C++ / C Code:
will always result in a value of r that is greater than or equal to zero and is less than or equal to n-1 (it's the remainder after performing the integer operation of dividing x by n.) |
|
#3
|
|||
|
|||
Re: Help with Dice programQuote:
These statements have absolutely no effect on any results in this program. What are you really trying to do with them? (Don't make us guess; tell us.) Did your compiler have any messages? What compiler? Regards, Dave |
|
#4
|
|||
|
|||
Re: Help with Dice programI was just trying stuff out to see if it would change anything but it didn't and there were no compiler errors the program would just keep rolling 1000s
|
|
#5
|
|||
|
|||
Re: Help with Dice programI've changed it and now it wont do nothing and an error comes up.It compiles but there must be an error. Any help
CPP / C++ / C Code:
|
|
#6
|
|||
|
|||
Re: Help with Dice programQuote:
In C (or C++) you must assign a value to a variable before using that variable in an expression. If you want n to be equal to 6, then you could try: CPP / C++ / C Code:
Your program doesn't assign a value to n. What value would you expect the program to use? How could it possibly know? Look at your code and think about what you are trying to get it to do. Regards, Dave |
Recent GIDBlog
Toyota - 2008 November Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| BOOKEEPING program, HELP!! | yabud | C Programming Language | 10 | 17-Nov-2006 04:48 |
| Pipeline freeze simulation | darklightred | C++ Forum | 6 | 27-Jul-2006 20:37 |
| How to read particular memory location ? | realnapster | C Programming Language | 10 | 10-May-2006 10:11 |
| Dice rolling program (random number generator) | crystalattice | Python Forum | 1 | 17-Apr-2006 18:34 |
| Type casts ? | kai85 | C++ Forum | 12 | 23-Jun-2005 13:04 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The