Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help! There is an error in my WPF project I made in Visual Studio. It is only creating arrays filled with 0s, rather than

Please help! There is an error in my WPF project I made in Visual Studio. It is only creating arrays filled with 0s, rather than random numbers between 1 - 100 like it's supposed to.

My MainWindow.xaml.cs code:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes;

namespace PickLarger { ///

/// Interaction logic for MainWindow.xaml ///

public partial class MainWindow : Window { // define two arrays int[] array1 = new int[100]; int[] array2 = new int[100];

// random function Random r = new Random();

// initialize variables int right = 0; int wrong = 0; int x, y, index;

public MainWindow() { InitializeComponent(); }

private void MainWindow_Load(object sender, EventArgs e) { reset(); }

private void Button1_Click(object sender, RoutedEventArgs e) { // show numbers Number1.Text = x.ToString(); Number2.Text = y.ToString();

if (x >= y) right++; else wrong++;

// show results rightCount.Text = right.ToString(); wrongCount.Text = wrong.ToString(); }

private void Button2_Click(object sender, RoutedEventArgs e) { // show numbers Number1.Text = x.ToString(); Number2.Text = y.ToString();

if (y >= x) right++; else wrong++;

// show results rightCount.Text = right.ToString(); wrongCount.Text = wrong.ToString(); }

// display results after next button is clicked private void Next_Click(object sender, RoutedEventArgs e) { Number1.Text = "?"; Number2.Text = "?";

// check if user has played 100 games if (index == 100) reset(); else { index++; x = array1[index]; y = array2[index]; }

button1.IsEnabled = true; button2.IsEnabled = true; }

// reset if 100 games were played public void reset() { index = 0; right = 0; wrong = 0;

// initialize arrays for (int i = 0; i

x = array1[0]; y = array2[0]; } } }

When program is run:

image text in transcribed

Assignment that I made the WPF project for:

Create a WPF project named PickLarger 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. The following screenshots are before and after the player makes a guess.

one will contain 2 0 Right: 1 Wrong: 0 0 Next

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Effective Delivery Effective

Answered: 1 week ago