this small part of program generate 2 random values in loop loop infinite amount of times until condition met. generate 2 values add 2 values totalnum, totalnum passed pointmatch variable. need pointmatch take in first total keep same exact number throughout program. after next generation of numbers generated added total. need check if total equal previous pointmatch, if not generate new numbers again until condition met. cant seem keep pointmatch same, equal total.
the problem ware trying achieve goal simple through complicated approach, if want pointmatch
remain same, don't generate second random value through rand()
instead, subtract first 1 pointmatch
.
int rolldice() { /* wrong: call once in whole program */ srand( time( null )); /* pick random value */ randvalue = 1 + rand() % 6; secondrandvalue = pointmatch - randvalue; return randvalue + secondrandvalue; //return random total }
also, seems though variables globals , bad sign.
this result random default random number generator can generate random numbers both randvalue
, secondrandvalue
, if have argument against approach, please share it.
Comments
Post a Comment