OK, Im trying to make a game that rolls die... currently i have tried doing rand() by time... but this causes the same seconds to be used in srand() because of compile time, which in turn makes the same values for each die.
How would I go about randomizing 2 integer variables in the same program instance?
Any suggestions on newbish techniques? or other ways of doing specific tasks?Code:#include <iostream> #include <time.h> using namespace std; void Menu(); void GameLoop(); int rollDie(); int randomize(); int firstRoll(); void makePoint(int point); int die1; int die2; int diesum; bool done=false; int main() { Menu(); cin.get(); return 0; } void Menu() { char answer; cout<<"\n\t\tWelcome to Craps!\n"; cout<<"\t\t (P) to Play\n"; cout<<"\t\t (Q) to Quit\n"; cout<<"\t\t -->: "; cin>>answer; if(answer == 'P' || answer == 'p') { GameLoop(); } if(answer == 'q' || answer == 'Q') { cout<<"\t\tThank You for playing Craps!\n"; cout<<"\t\t Quitting....."; done=true; } } void GameLoop() { int result; while(!done) { result=firstRoll(); makePoint(result); } } int randomize() { time_t seconds; srand((unsigned)time(&seconds)); return (rand() % (6-3+1*3)+1); } int rollDie(int die1, int die2) { int diesum; die1 = randomize(); die2 = randomize(); diesum=die1+die2; cout<<"\t\tYou have rolled a "<<die1<<" and a "<<die2<<"\n"; cout<<"\t\tWith a sum of >>>> "<<diesum<<" <<<<"<<"\n"; return diesum; } int firstRoll() { int die1, die2; diesum = rollDie(die1,die2); if(diesum == 7 || diesum == 11) { cout<<"\t\t\tYou win!\n"; cin.get(); return 0; } else if(diesum == 2 || diesum == 3 || diesum == 12) { cout<<"\t\t\tYou lose!\n"; cin.get(); return -1; } else { cout<<"\t\t\tKeep rolling!\n"; cin.get(); return diesum; } } void makePoint(int point) { done=true; cout<<"\t\tMakePoint!"; }