I cannot figure out where to put in randomize(); in this code so that the numbers are truly random. I can only get them to stay the same for a long time and then change by 1, or change by 1 each time, or sometimes not change at all. Here is my code...
Note that fight is a function I call, and that the //1, //2, etc. was just for me to fix some problems with missing brackets.
Code:
if (choice1 == 1) {
cout<<"He grunts, turns around, and stumbles towards you."<<endl;
fight (health,stoner_health);}
}
return 0;
}
fight (int fighter1, int fighter2)
{//1
int fight_choice;
while (fighter2>0 || fighter1>0) {
cout<<"Do you want to Punch(1) or Kick(2)?"<<endl;
cin>>fight_choice;
switch(fight_choice) {//2
case 1: {//3
int strike;
strike = random(5);
int damage;
damage = random(5);
cout<<"You punch for "<< damage << " damage."<<endl;
fighter2 = fighter2 - damage;
cout<<"They are down to "<< fighter2 << " health"<<endl;
cout<<"They attack you for " << strike << " damage."<<endl;
fighter1 = fighter1 - strike;
cout<<"You are down to " << fighter1 << " health."<<endl;
getch();
clrscr(); }//3
break;
case 2: {//4
int strike2;
strike2 = random(8);
int damage2;
damage2 = random(8);
cout<<"You kick for "<< damage2 << " damage, but leave yourself open for attack."<<endl;
fighter2 = fighter2 - damage2;
cout<<"They are down to "<< fighter2 << " health"<<endl;
cout<<"They attack you for " << strike2 << " damage."<<endl;
fighter1 = fighter1 - strike2;
cout<<"You are down to " << fighter1 << " health."<<endl;
getch();
clrscr();
break; }//4
}//2
}