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

Hi I have started on a slot machine for my class, but I am stuck on how to show

ID: 3684135 • Letter: H

Question

Hi I have started on a slot machine for my class, but I am stuck on how to show a display of the total amount that been use, and how much you won. I show you how I did mine, but then I am stuck on the adding or stacking the button click where if u bet $5 on the text, then it should add up the $5 each time on the label each time u press the button, and it should show you how much won, if you win. I show you mine, and I am wondering if someone can show an example how to stack up the $ on the text each time the user press the button, and it should show the winning amount on the label. I am using Visual Studio C# WPF.

public partial class MainWindow : Window
{

public MainWindow()
{
InitializeComponent();
}

private void btnStart_Click(object sender, RoutedEventArgs e)
{
  
//string imageName = "Affirmed.jpg";
var pathStr = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var destinationPathFolder = pathStr + "\SlotImage";

//Random imgbox1
string[] fileArray = Directory.GetFiles(destinationPathFolder);
Random rnd = new Random();
int index = rnd.Next(0, fileArray.Length);

var destinationuri = new Uri(fileArray[index]);
imgbox1.Source = new BitmapImage(destinationuri);

//Random imgbox2
string[] fileArray2 = Directory.GetFiles(destinationPathFolder);
Random rnd2 = new Random();
int index2 = rnd.Next(0, fileArray2.Length);

var destinationuri2 = new Uri(fileArray[index2]);
imgbox2.Source = new BitmapImage(destinationuri2);

//Random imgbox3
string[] fileArray3 = Directory.GetFiles(destinationPathFolder);
Random rnd3 = new Random();
int index3 = rnd.Next(0, fileArray3.Length);

var destinationuri3 = new Uri(fileArray[index3]);
imgbox3.Source = new BitmapImage(destinationuri3);

double Winning;
double Winning1;
double Winning2;
double Winning3;
  
try
{
Winning = double.Parse(txtAmount.Text);
Winning1 = Winning * 2;
Winning2 = Winning * 2;
Winning3 = Winning * 3;

//Display the winning if all the number are equal x3
if (index == index2 && index2 == index3)
{
lblWinning.Content = "You Won " + Winning3.ToString("c");
}
//Display the winning if two number equal x2
else if (index == index2)
{
lblWinning.Content = "You Won " + Winning2.ToString("c");
}
//Display the winning if two number equal x2
else if (index2 == index3)
{
lblWinning.Content = "You Won " + Winning1.ToString("c");
}
//Display if there is no equal
else
{
lblWinning.Content = "You Lost";
}

  
}
catch
{
MessageBox.Show("Please Enter An Amount");
}

  
}


private void btnExit_Click(object sender, RoutedEventArgs e)
{
//Display the message
MessageBox.Show("How much you bet " + lblBet2.Content);
MessageBox.Show("How much you win" + lblWin2.Content);

//This is the Exit for the main screen
this.Close();
}


}
}

Explanation / Answer

using System;

public partial class MainWindow : Window
    {
     
        public MainWindow()
        {
            InitializeComponent();
        }

        private void btnStart_Click(object sender, RoutedEventArgs e)
        {
          
            //string imageName = "Affirmed.jpg";
            var pathStr = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var destinationPathFolder = pathStr + "\SlotImage";

            //Random imgbox1
            string[] fileArray = Directory.GetFiles(destinationPathFolder);
            Random rnd = new Random();
            int index = rnd.Next(0, fileArray.Length);

            var destinationuri = new Uri(fileArray[index]);
            imgbox1.Source = new BitmapImage(destinationuri);

            //Random imgbox2
            string[] fileArray2 = Directory.GetFiles(destinationPathFolder);
            Random rnd2 = new Random();
            int index2 = rnd.Next(0, fileArray2.Length);

            var destinationuri2 = new Uri(fileArray[index2]);
            imgbox2.Source = new BitmapImage(destinationuri2);

            //Random imgbox3
            string[] fileArray3 = Directory.GetFiles(destinationPathFolder);
            Random rnd3 = new Random();
            int index3 = rnd.Next(0, fileArray3.Length);

            var destinationuri3 = new Uri(fileArray[index3]);
            imgbox3.Source = new BitmapImage(destinationuri3);

            double Winning;
            double Winning1;
            double Winning2;
            double Winning3;
          
            try
            {
                Winning = double.Parse(txtAmount.Text);
                Winning1 = Winning * 2;
                Winning2 = Winning * 2;
                Winning3 = Winning * 3;

                //Display the winning if all the number are equal x3
                if (index == index2 && index2 == index3)
                {
                    lblWinning.Content = "You Won " + Winning3.ToString("c");
                }
                    //Display the winning if two number equal x2
                else if (index == index2)
                {
                    lblWinning.Content = "You Won " + Winning2.ToString("c");
                }
                    //Display the winning if two number equal x2
                else if (index2 == index3)
                {
                    lblWinning.Content = "You Won " + Winning1.ToString("c");
                }
                    //Display if there is no equal
                else
                {
                    lblWinning.Content = "You Lost";
                }

              
            }
            catch
            {
                MessageBox.Show("Please Enter An Amount");
            }

          
        }


        private void btnExit_Click(object sender, RoutedEventArgs e)
        {
           If sender Is Button1 Then
                //Display the message
           int count++; // here increment the count of the button click then multiply with the amount.
           lblBet2*count;

            MessageBox.Show("How much you bet " + lblBet2.Content);
            MessageBox.Show("How much you win" + lblWin2.Content);

            //This is the Exit for the main screen
            this.Close();
        }

     
    }

Please observe a small chnge is needede to do this