Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a C# WPF project named that contains two randomly generated arrays, each

ID: 3721987 • Letter: C

Question

Create a C# WPF project named that contains two randomly generated arrays, each containing 100 numbers. Include two Buttons labeled 1 and 2. Starting with position 0 in each array, ask the user to guess which of the two arrays contains the higher number and to click one of the two buttons to indicate the guess. After each button click, the program displays the values of the two compared numbers, as well as running counts of the number of correct and incorrect guesses. After the user makes a guess, disable the Buttons while the user views the results. After clicking a Next Button, the user can make another guess using the next two array values. If the user makes more than 100 guesses, the program should reset the array subscript to 0 so the comparisons start over but continue to keep a running score.

Explanation / Answer

Program:

namespace c# WPF

{

public partial class Form1:Form

{

int[] array1=new int[100];

int[] array2=new int[100];

Random randomObject =new Random();

static readonly string nl=Environment.NewLine;

int guess =0;

int index=0;

int correct=0;

int incorrect=0;

private void fillArray(int[] arrayToFill)

{

for (int i=0;i<arrayToFill.Length;i++)

{

arrayToFill[i]=randomObject.Next(1000);

}

}

private void displayResults(int number,bool isCorrect)

{

btn1.Enabled=false;

btn2.Enabled=false;

btnNext.Enabled=true;

string message="Number 1 is " +array1[index].ToString()+ nl;

message +="Number 2 is " +array2[index].ToString()+ nl+nl;

string s=isCorrect? "correct":"incorrect";

message+="You guessed number"+number +"which is"+s+nl+nl;

message+="Total correct"+correct.ToString()+nl;

message+="Total incorrect"+incorrect.Tostring();

MessageBox.show(message);

guess++;

index++;

if(index==100)index=0;

}

public Form1()

{

initializeComponent();

}

private void Form1_Load(object sender,EventArgs e)

{

fillArray(array1);

fillArray(array2);

btn1.Enabled=false;

btn2.Enabled=false;

}

private void btnNext_Click(object sender,EventArgs e)

{

string message ="Guess"+(guess+1).ToString()+nl+nl;

message+="Which number is higher?"+nl+nl;

message+="Press button 1 or button 2";

MessageBox.Show(message);

btn1.Enabled=true;

btn2.Enabled=true;

btnNext.Enabled=false;

}

private void btn1_Click(object sender,EventArgs e)

{

if(array1[index]>array2[index])

{

correct++;

displayResults(1,true);

}

else

{

incorrect++;

displayResults(1,false);

}

}

private void btn2_Click(object sender,EventArgs e)

{

if(array2[index]>array1[index])

{

correct++;

displayResults(2,true);

}

else

{

incorrect++;

displayResults(2,false);

}

}

}

}