I'm still learning to program. This is the first practical application I've tried to write outside of copying from my textbook. I thought it'd be something easy and within my ability, but it's turning out not so much.

I'ts a simple command line "dice roller" where two people roll 2 six sided dice each and compare the result (with some wrinkles, but those haven't been programmed in yet).

Here's a slimmed down version so you can see what I'm doing.

What I'm getting as an output, though, is something like:Code:using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static int GenericAttack() { Random myRandom = new Random(); int die1 = myRandom.Next(1, 6); int die2 = myRandom.Next(1, 6); int attackTotal = die1 + die2; Console.WriteLine("The attacking character rolls a {0} and {1} for a total of {2}", die1, die2, attackTotal); return attackTotal; } static int GenericDefend() { Random myRandom = new Random(); int die1 = myRandom.Next(1, 6), die2 = myRandom.Next(1, 6); int attackTotal = die1 + die2; Console.WriteLine("The defending character rolls a {0} and {1} for a total of {2}", die1, die2, attackTotal); return attackTotal; } static int Fight() { int attackTotal = 0, defendTotal = 0; attackTotal = GenericAttack(); defendTotal = GenericDefend(); if (attackTotal > defendTotal) return 1; else if (attackTotal < defendTotal) return 2; else return 0; } static void Main(string[] args) { Random myRandom = new Random(); Console.WriteLine("Let's Fight!"); int winner = 0; while (winner == 0) { winner = Fight(); } if (winner == 1) Console.WriteLine("The attacking Character wins!"); else if (winner == 2) Console.WriteLine("The defending Character wins!"); else Console.WriteLine("Something went horribly wrong!"); Console.ReadKey(); } } }

So, at first I thought somehow the die1 and die2 variables were carrying over between functions, even though they shouldn't. But renaming the variables didn't help. Nor did renaming the myRandom methods to something like attackRandom and defendRandom.Code:Let's Fight! The attacking character rolls a 1 and 4 for a total of 5 The defending character rolls a 1 and 4 for a total of 5 The attacking character rolls a 1 and 4 for a total of 5 The defending character rolls a 1 and 4 for a total of 5 The attacking character rolls a 1 and 4 for a total of 5 The defending character rolls a 1 and 4 for a total of 5 The attacking character rolls a 1 and 4 for a total of 5 The defending character rolls a 1 and 4 for a total of 5 The attacking character rolls a 1 and 4 for a total of 5 The defending character rolls a 1 and 4 for a total of 5 The attacking character rolls a 1 and 4 for a total of 5 The defending character rolls a 1 and 4 for a total of 5 The attacking character rolls a 1 and 4 for a total of 5 The defending character rolls a 1 and 4 for a total of 5 The attacking character rolls a 1 and 4 for a total of 5 The defending character rolls a 1 and 4 for a total of 5 The attacking character rolls a 1 and 4 for a total of 5 The defending character rolls a 1 and 4 for a total of 5 The attacking character rolls a 1 and 4 for a total of 5 The defending character rolls a 1 and 4 for a total of 5 The attacking character rolls a 1 and 4 for a total of 5 The defending character rolls a 1 and 4 for a total of 5 The attacking character rolls a 1 and 4 for a total of 5 The defending character rolls a 1 and 4 for a total of 5 The attacking character rolls a 1 and 4 for a total of 5 The defending character rolls a 1 and 4 for a total of 5 The attacking character rolls a 1 and 4 for a total of 5 The defending character rolls a 1 and 4 for a total of 5 The attacking character rolls a 1 and 4 for a total of 5 The defending character rolls a 1 and 4 for a total of 5 The attacking character rolls a 1 and 4 for a total of 5 The defending character rolls a 1 and 4 for a total of 5 The attacking character rolls a 1 and 4 for a total of 5 The defending character rolls a 3 and 2 for a total of 5 The attacking character rolls a 3 and 2 for a total of 5 The defending character rolls a 3 and 2 for a total of 5 The attacking character rolls a 3 and 2 for a total of 5 The defending character rolls a 3 and 2 for a total of 5 The attacking character rolls a 3 and 2 for a total of 5 The defending character rolls a 3 and 2 for a total of 5 The attacking character rolls a 3 and 2 for a total of 5 The defending character rolls a 3 and 2 for a total of 5 The attacking character rolls a 3 and 2 for a total of 5 The defending character rolls a 3 and 2 for a total of 5 The attacking character rolls a 3 and 2 for a total of 5 The defending character rolls a 3 and 2 for a total of 5 The attacking character rolls a 3 and 2 for a total of 5 The defending character rolls a 3 and 2 for a total of 5 The attacking character rolls a 3 and 2 for a total of 5 The defending character rolls a 3 and 2 for a total of 5 The attacking character rolls a 3 and 2 for a total of 5 The defending character rolls a 3 and 2 for a total of 5 The attacking character rolls a 3 and 2 for a total of 5 The defending character rolls a 3 and 2 for a total of 5 The attacking character rolls a 3 and 2 for a total of 5 The defending character rolls a 3 and 2 for a total of 5 The attacking character rolls a 3 and 2 for a total of 5 The defending character rolls a 3 and 2 for a total of 5 The attacking character rolls a 3 and 2 for a total of 5 The defending character rolls a 3 and 2 for a total of 5 The attacking character rolls a 3 and 2 for a total of 5 The defending character rolls a 3 and 2 for a total of 5 The attacking character rolls a 3 and 2 for a total of 5 The defending character rolls a 3 and 2 for a total of 5 The attacking character rolls a 3 and 2 for a total of 5 The defending character rolls a 3 and 2 for a total of 5 The attacking character rolls a 3 and 2 for a total of 5 The defending character rolls a 3 and 2 for a total of 5 The attacking character rolls a 3 and 2 for a total of 5 The defending character rolls a 3 and 2 for a total of 5 The attacking character rolls a 3 and 2 for a total of 5 The defending character rolls a 3 and 2 for a total of 5 The attacking character rolls a 2 and 4 for a total of 6 The defending character rolls a 2 and 4 for a total of 6 The attacking character rolls a 2 and 4 for a total of 6 The defending character rolls a 2 and 4 for a total of 6 The attacking character rolls a 2 and 4 for a total of 6 The defending character rolls a 2 and 4 for a total of 6 The attacking character rolls a 2 and 4 for a total of 6 The defending character rolls a 2 and 4 for a total of 6 The attacking character rolls a 2 and 4 for a total of 6 The defending character rolls a 2 and 4 for a total of 6 The attacking character rolls a 2 and 4 for a total of 6 The defending character rolls a 2 and 4 for a total of 6 The attacking character rolls a 2 and 4 for a total of 6 The defending character rolls a 2 and 4 for a total of 6 The attacking character rolls a 2 and 4 for a total of 6 The defending character rolls a 2 and 4 for a total of 6 The attacking character rolls a 2 and 4 for a total of 6 The defending character rolls a 2 and 4 for a total of 6 The attacking character rolls a 2 and 4 for a total of 6 The defending character rolls a 2 and 4 for a total of 6 The attacking character rolls a 2 and 4 for a total of 6 The defending character rolls a 2 and 4 for a total of 6 The attacking character rolls a 2 and 4 for a total of 6 The defending character rolls a 2 and 4 for a total of 6 The attacking character rolls a 2 and 4 for a total of 6 The defending character rolls a 2 and 4 for a total of 6 The attacking character rolls a 2 and 4 for a total of 6 The defending character rolls a 2 and 4 for a total of 6 The attacking character rolls a 2 and 4 for a total of 6 The defending character rolls a 2 and 4 for a total of 6 The attacking character rolls a 2 and 4 for a total of 6 The defending character rolls a 2 and 4 for a total of 6 The attacking character rolls a 2 and 4 for a total of 6 The defending character rolls a 2 and 4 for a total of 6 The attacking character rolls a 2 and 4 for a total of 6 The defending character rolls a 2 and 4 for a total of 6 The attacking character rolls a 2 and 4 for a total of 6 The defending character rolls a 2 and 4 for a total of 6 The attacking character rolls a 2 and 4 for a total of 6 The defending character rolls a 2 and 4 for a total of 6 The attacking character rolls a 2 and 4 for a total of 6 The defending character rolls a 2 and 4 for a total of 6 The attacking character rolls a 2 and 4 for a total of 6 The defending character rolls a 4 and 3 for a total of 7 The defending Character wins!

It also never happens when I try to Step Into the functions while debugging (though it always happens when I step over). Grrrr. Can someone tell me what's going wrong? Thanks!

Tweet This+ 1 thisPost To Linkedin