visual studio - Basic while loop c# -


i have problem work out in 2 hypothetical oppenents dueling rpg style. asked give them hp , each round of loop hp lost respectiviely oppenent has hit them for. i've got basic understanding numbers keep on repeating. working on visual studios 15. in advance!

/*fighter 1 charlie unicorn  *fighter 2 nyan cat  *fighter 1 has 100 hp  *fighter 2 has 150 hp  *fighter 1 can hit hard 15hp each turn  *fighter 2 can hit hard 10hp each turn */  //who wins fight  int fighteronehealth = 100; int fightertwohealth = 150; random randomizer = new random(); while (fighteronehealth > 0 || fightertwohealth > 0) {           int fonerandomhit;     int ftworandomhit;     fonerandomhit = randomizer.next(0, 15);     ftworandomhit = randomizer.next(0, 10);     int fightonehploss = fighteronehealth - ftworandomhit;     int fighttwohploss = fightertwohealth - fonerandomhit;     console.writeline("after attack: charlie unicorn hp: {0}, nyan cat hp: {1}", fightonehploss, fighttwohploss); } 

you're declaring new variables inside loop:

int fightonehploss = fighteronehealth - ftworandomhit; int fighttwohploss = fightertwohealth - fonerandomhit; 

... you're never modifying variables meant represent players' current health. don't need variables @ - need reduce health:

fighteronehealth -= ftworandomhit; fightertwohealth -= fonerandomhit; console.writeline("after attack: charlie unicorn hp: {0}, nyan cat hp: {1}",     fighteronehealth, fightertwohealth); 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -