Possible Duplicate:
Problems with srand(), C++
Basically, the random number I am generating is inclining in size, everytime it is used inside my while loop. It being random, should't incline and not be random as such. The variable hit is defined by the random number. But as I said, the random number is not random. Also, as the random number gets bigger it goes over the limit I set for it.
//Code im using for random number :
srand((unsigned)time(0));
hit = rand()%15;
//The subject for the problem :
while (1) {
if (mon1==0) {
cout << "A dragon appears." << endl;
system ("pause");
cout << "Enter 1 to attack and 2 to run away, " <<name << endl;
cin >> act;
if (act==2) {
cout << "You run away. " << endl;
}
if (act==1) {
cout << " You choose to attack! Good luck " << endl;
}
}
if (mon1==1) { // orc
srand((unsigned)time(0));
hit = rand()%15;
ehealth = (100);
cout << " A orc appears" << endl;
system ("pause");
cout << "Enter 1 to attack and 2 to run away, " <<name << endl;
cin >> act;
system ("cls");
if (act==2) {
cout << "You run away. " << endl;
system ("cls");
}
if (act==1) { // ATTACK HERE MAIN ATTACk TESING !!!!!!!!!!!!!!!!!!!!!!! ORC
cout << " You choose to attack! Good luck " << endl;
cout << " Your health is " << health << endl;
cout << " The enemys health is " << ehealth << endl;
cout << " You have 3 abilitys." << endl;
while (1) {
cout << " Press 1 to swipe, 2 to block the enemys attack and 3 to use your special attack" <<endl;
cin >> act1;
system ("cls");
if (act1==1) {
cout << " You swipe the enemy " << endl; // swipe
cout << " You hit for " << hit << endl;
if (wep==1) {
hit = (hit + 4);
cout << " As you are the axe i will add on 4 to that, making " << hit << endl; // axe
}
ehealth = (ehealth - hit);
cout << " The enemys health is " << ehealth << endl;
cout << " Your health is " << health << endl;
system ("pause");
}
if (act1==2) {
cout <<" You block, making you immune to the next attack" << endl; //block
ehit = (0);
//newrand
cout << " Your health is " << health << endl;
cout << " The enemys health is " << ehealth << endl;
}
if (act1==3) {
cout << " Special attack is being worked on BUDDY, GUY, FRIEND!! " << endl;
}
system ("pause");
if (health < 0) {
cout << "You died, sorry!" << endl;
}
if (ehealth < 0) {
cout << " Yay! You killed the enemy!" << endl;
}
if (health == 0) {
cout << "You died, sorry!" << endl;
}
if (ehealth == 0) {
cout << " Yay! You killed the enemy!" << endl;
}
cout << " Now it is the enemys turn! " << endl;
health = ( health - ehit );
cout << " The enemy hits you for a " << ehit << endl;
cout << " Your health is now " << health << endl;
srand((unsigned)time(0));
ehit = rand()%10;
system ("pause");
system ("cls");
}
// END OF ORC
}
}