I am getting a error when trying to create a Form that will randomly display 3 values of 3 Dice for 2 players and will compare the numbers and displays who won. The is running great but it started show me an error after I put the IF statement. The code runs but it returns the error when I click on "Play!" button.
The problem is that I am not getting any error in the "Error List" so the program is running but when I click on "Play" it freezes and pops up the error message "System.FormatException: 'Input string was not in a correct format" at the line:
int P1R = Convert.ToInt32(Player1_Result.Text); . I believe that my issue is in Int and String... I ran the debugger but not getting anywhere.
Can you please help... thanks
Dice1_input_Player1.Text = dice_Player1[0].ToString();
Dice2_input_Player1.Text = dice_Player1[1].ToString();
Dice3_input_Player1.Text = dice_Player1[2].ToString();
Dice1_input_Player2.Text = dice_Player2[0].ToString();
Dice2_input_Player2.Text = dice_Player2[1].ToString();
Dice3_input_Player2.Text = dice_Player2[2].ToString();
Player1_Result.Text = string.Format("Player 1: {0}{1}{2}", Dice1_input_Player1.Text, Dice2_input_Player1.Text, Dice3_input_Player1.Text);
Player2_Result.Text = string.Format("Player 2: {0}{1}{2}", Dice1_input_Player2.Text, Dice2_input_Player2.Text, Dice3_input_Player2.Text);
int P1R = Convert.ToInt32(Player1_Result.Text);
int P2R = Convert.ToInt32(Player2_Result.Text);
if (P1R >= P2R)
Console.Write("Player 1 Wins!");
else
Console.Write("Player 2 Wins!");
The problem is that I am not getting any error in the "Error List" so the program is running but when I click on "Play" it freezes and pops up the error message "System.FormatException: 'Input string was not in a correct format" at the line:
int P1R = Convert.ToInt32(Player1_Result.Text); . I believe that my issue is in Int and String... I ran the debugger but not getting anywhere.
Can you please help... thanks
Dice1_input_Player1.Text = dice_Player1[0].ToString();
Dice2_input_Player1.Text = dice_Player1[1].ToString();
Dice3_input_Player1.Text = dice_Player1[2].ToString();
Dice1_input_Player2.Text = dice_Player2[0].ToString();
Dice2_input_Player2.Text = dice_Player2[1].ToString();
Dice3_input_Player2.Text = dice_Player2[2].ToString();
Player1_Result.Text = string.Format("Player 1: {0}{1}{2}", Dice1_input_Player1.Text, Dice2_input_Player1.Text, Dice3_input_Player1.Text);
Player2_Result.Text = string.Format("Player 2: {0}{1}{2}", Dice1_input_Player2.Text, Dice2_input_Player2.Text, Dice3_input_Player2.Text);
int P1R = Convert.ToInt32(Player1_Result.Text);
int P2R = Convert.ToInt32(Player2_Result.Text);
if (P1R >= P2R)
Console.Write("Player 1 Wins!");
else
Console.Write("Player 2 Wins!");