Im making this game and i have a problem with srand
Dec 27, 2012 at 4:18pm UTC
I programmed it to ask you what move do u want to make, then the opponent makes a random number from 1-10 but when i test it it sends out all the if statements
any idea? here's the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
srand (time(NULL));
oSec = rand() % 10 + 1;
if (oSec = 1)
{cout << "Sasuke's turn\n" ;
cout << "Chidori!" << endl;
m_HP -= 15;
o_Chakra -= 10;
cout << "Your HP is " << m_HP << endl;}
if (oSec = 2)
{cout << "Sasuke's turn\n" ;
cout << "Think fast!\n" ;
m_HP -= 5;
cout << "Your HP is " << m_HP << endl;}
if (oSec = 3)
{cout << "Sasuke's turn\n" ;
cout << "He's Waiting for you\n" ;
o_Chakra += 10;}
if (oSec = 4)
{cout << "Sasuke's turn\n" ;
cout << "He's taking this chance to heal himself too\n" ;
o_HP += 10;}
if (oSec = 5)
{cout << "Sasuke's turn\n" ;
cout << "Amaterasu!\n" ;
m_HP -= 19;
cout << "Your HP is " << m_HP << endl;}
if (oSec = 6)
{cout << "Sasuke's turn\n" ;
cout << "Sharingan!\n" ;
cout << "You'ce been caught in a Genjutsu\n" ;
m_Chakra -= 17;
cout << "Your Chakra is " << m_Chakra << endl;}
if (oSec = 7)
{cout << "Sasuke's turn\n" ;
cout << "Katon Seida Kon No Jutsu\n" ;
cout << "You've been injured\n" ;
m_HP -= 100;}
Dec 27, 2012 at 4:47pm UTC
Use == to compare if something is equal to something. = is for assignment.
Dec 27, 2012 at 5:00pm UTC
I love you Peter
Topic archived. No new replies allowed.