+ 1

Не работает последний кусок программы. Пожалуйста подскажите почему.

static void Main(string[] args) { Random rnd = new Random(); int local = rnd.Next(3); int mhp; int ma; int php = 100; int pa = 10; switch (local) { case 1: mhp = 9; ma = 5; Console.WriteLine("mob1 lvl"); Console.WriteLine("hp {0}" ,mhp); Console.WriteLine("attack {0}" ,ma); break; case 2: mhp = 12; ma = 10; Console.WriteLine("mob2lvl"); Console.WriteLine("hp {0}" ,mhp); Console.WriteLine("attack {0}" ,ma); break; case 3: Console.WriteLine("box"); break; } while (mhp > 0){ mhp - pa = mhp; php - ma = php; }

17th Feb 2019, 11:31 AM
Андрей Бабурин
Андрей Бабурин - avatar
3 Respostas
+ 1
И? Мне нужно, чтобы выражение работало, а не просто ее запуск. Когда local 1 или 2 mhp >0 выражение не работает.
18th Feb 2019, 4:49 AM
Андрей Бабурин
Андрей Бабурин - avatar
0
The equation should on the left of the equal sign. So mhp = mhp - pa pleae put you code in the playground and post a link. That way we can help you better.
17th Feb 2019, 11:53 AM
sneeze
sneeze - avatar
0
I had a second look at your code. The sololearn compiler complains about ma mhp being not initialized so please change this to ma = 0; mhp= 0; if that is appropriate just a default value to get the values 1,2,3 from rnd.Next, please use these parameters int local = rnd.Next(1,4); Added a debug line in the while-loop to see if this is running. Also changed the equation in the while-loop mhp = mhp - pa; php = php - ma; Hope the code now does what you want it to do. Or that you can fix the code to what you want it to be. https://code.sololearn.com/cNrIB6SSp7io
18th Feb 2019, 9:39 PM
sneeze
sneeze - avatar