Question: I am getting an error at if (compChoice == 1), else if (compChoice == 2),else if (compChoice == 3). Can you please fix my code?

I am getting an error at "if (compChoice == 1)", "else if (compChoice == 2)","else if (compChoice == 3)". Can you please fix my code? This is in C#.

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;

namespace WindowsFormsApp8 { public partial class rockPaperScissors : Form { public rockPaperScissors() { InitializeComponent(); } private void DisplayWinner() { if ((txtYourChoice.Text == "Rock" && txtCompChoice.Text == "Scissors") || (txtYourChoice.Text == "Scissors" && txtCompChoice.Text == "Rock")) { txtResult.Text = "Rock Wins"; } else if ((txtYourChoice.Text == "Scissors" && txtCompChoice.Text =="Paper") || (txtYourChoice.Text =="Paper" && txtCompChoice.Text == "Scissors")) { txtResult.Text = "Scissors wins"; } else if ((txtYourChoice.Text =="Paper" && txtCompChoice.Text =="Rock") || (txtYourChoice.Text =="Rock" && txtCompChoice.Text == "Paper")) { txtResult.Text = "Paper wins"; } else if (((txtYourChoice.Text=="Paper") && (txtCompChoice.Text=="Paper")) || ((txtYourChoice.Text=="Rock") && (txtCompChoice.Text=="Rock")) || ((txtYourChoice.Text=="Scissors") && (txtCompChoice.Text == "Scissors"))) { txtResult.Text = "It's a tie"; MessageBox.Show("Play Again", "It's a tie", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } private void RandomNoGenerator() { Random rnd = new Random(); int compChoice = rnd.Next(1, 4); }

private void label1_Click(object sender, EventArgs e) {

}

private void rockPaperScissors_Load(object sender, EventArgs e) {

}

private void PicBoxRock_Click(object sender, EventArgs e) { txtYourChoice.Text = "Rock"; RandomNoGenerator(); if (compChoice == 1) txtCompChoice.Text = "Rock"; else if (compChoice == 2) txtCompChoice.Text = "Paper"; else if (compChoice == 3) txtCompChoice.Text = "Scissors"; DisplayWinner(); }

private void picBoxPaper_Click(object sender, EventArgs e) { txtYourChoice.Text = "Paper"; RandomNoGenerator(); if (compChoice == 1) txtCompChoice.Text = "Rock"; else if (compChoice == 2) txtCompChoice.Text = "Paper"; else if (compChoice == 3) txtCompChoice.Text = "Scissors"; DisplayWinner(); }

private void picBoxScissors_Click(object sender, EventArgs e) { txtYourChoice.Text = "Scissors"; RandomNoGenerator(); if (compChoice == 1) txtCompChoice.Text = "Rock"; else if (compChoice == 2) txtCompChoice.Text = "Paper"; else if (compChoice == 3) txtCompChoice.Text = "Scissors"; DisplayWinner(); } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!