Question

C#: I am working on this application and keep running into this error. Please help me fix it.

Error:

Form 1.cs ผื -p X Form1.csLDesign] ū SinghAjayProgram08 Form1 spinButton_Click(object sender, EventArgse int pictureIhrea - r

Design:

Form 1.cs Form1.cs [Design] x Slot Machine Amount Inserted: Spin Exit 囤fruitsimageList

Code:

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 SinghAjayProgram08
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

double totalInserted = 0;
double totalWon = 0;

private void spinButton_Click(object sender, EventArgs e)
{
Random rand = new Random();

int index = rand.Next(fruitsImageList.Images.Count);

firstPictureBox.Image = fruitsImageList.Images[index];
secondPictureBox.Image = fruitsImageList.Images[index];
thirdPictureBox.Image = fruitsImageList.Images[index];

int pictureOne = rand.Next(0, 10);
int pictureTwo = rand.Next(0, 10);
int pictureThree = rand.Next(0, 10);

double amount = double.Parse(amountTextBox.Text);
totalInserted += amount;

// Picture one
if (pictureOne == 0)
{
firstPictureBox.Image = Image.FromFile("Apple.bmp");
}
else if (pictureOne == 1)
{
firstPictureBox.Image = Image.FromFile("Banana.bmp");
}
else if (pictureOne == 2)
{
firstPictureBox.Image = Image.FromFile("Cherries.bmp");
}
else if (pictureOne == 3)
{
firstPictureBox.Image = Image.FromFile("Grapes.bmp");
}
else if (pictureOne == 4)
{
firstPictureBox.Image = Image.FromFile("Lemon.bmp");
}
else if (pictureOne == 5)
{
firstPictureBox.Image = Image.FromFile("Lime.bmp");
}
else if (pictureOne == 6)
{
firstPictureBox.Image = Image.FromFile("Orange.bmp");
}
else if (pictureOne == 7)
{
firstPictureBox.Image = Image.FromFile("Pear.bmp");
}
else if (pictureOne == 8)
{
firstPictureBox.Image = Image.FromFile("Strawberry.bmp");
}
else if (pictureOne == 9)
{
firstPictureBox.Image = Image.FromFile("Watermelon.bmp");
}

// Picture two
if (pictureTwo == 0)
{
secondPictureBox.Image = Image.FromFile("Apple.bmp");
}
else if (pictureTwo == 1)
{
secondPictureBox.Image = Image.FromFile("Banana.bmp");
}
else if (pictureTwo == 2)
{
secondPictureBox.Image = Image.FromFile("Cherries.bmp");
}
else if (pictureTwo == 3)
{
secondPictureBox.Image = Image.FromFile("Grapes.bmp");
}
else if (pictureTwo == 4)
{
secondPictureBox.Image = Image.FromFile("Lemon.bmp");
}
else if (pictureTwo == 5)
{
secondPictureBox.Image = Image.FromFile("Lime.bmp");
}
else if (pictureTwo == 6)
{
secondPictureBox.Image = Image.FromFile("Orange.bmp");
}
else if (pictureTwo == 7)
{
secondPictureBox.Image = Image.FromFile("Pear.bmp");
}
else if (pictureTwo == 8)
{
secondPictureBox.Image = Image.FromFile("Strawberry.bmp");
}
else if (pictureTwo == 9)
{
secondPictureBox.Image = Image.FromFile("Watermelon.bmp");
}

// Picture three
if (pictureThree == 0)
{
thirdPictureBox.Image = Image.FromFile("Apple.bmp");
}
else if (pictureThree == 1)
{
thirdPictureBox.Image = Image.FromFile("Banana.bmp");
}
else if (pictureThree == 2)
{
thirdPictureBox.Image = Image.FromFile("Cherries.bmp");
}
else if (pictureThree == 3)
{
thirdPictureBox.Image = Image.FromFile("Grapes.bmp");
}
else if (pictureThree == 4)
{
thirdPictureBox.Image = Image.FromFile("Lemon.bmp");
}
else if (pictureThree == 5)
{
thirdPictureBox.Image = Image.FromFile("Lime.bmp");
}
else if (pictureThree == 6)
{
thirdPictureBox.Image = Image.FromFile("Orange.bmp");
}
else if (pictureThree == 7)
{
thirdPictureBox.Image = Image.FromFile("Pear.bmp");
}
else if (pictureThree == 8)
{
thirdPictureBox.Image = Image.FromFile("Strawberry.bmp");
}
else if (pictureThree == 9)
{
thirdPictureBox.Image = Image.FromFile("Watermelon.bmp");
}

if (pictureOne == pictureTwo && pictureOne == pictureThree)
{
totalWon += amount * 3;

MessageBox.Show("You Won" + (amount * 3).ToString("c"));
}
else if (pictureOne == pictureTwo || pictureOne == pictureThree
|| pictureTwo == pictureThree)
{
totalWon += amount * 2;

MessageBox.Show("You Won" + (amount * 2).ToString("c"));
}
else
{
MessageBox.Show("You Won" + 0.ToString("c"));
}
}
  
private void exitButton_Click(object sender, EventArgs e)
{
MessageBox.Show("Total Inserted" + " amount is" + totalInserted.ToString("c")
+ "\nTotal Winning amount is" + totalWon.ToString("c"));

this.Close();
}
}
}

Assignment:

A slot machine is a gambling device into which the user inserts money and then pulls a lever (or presses a button). The slot

Form 1.cs ผื -p X Form1.csLDesign] ū SinghAjayProgram08 Form1 spinButton_Click(object sender, EventArgse int pictureIhrea - rand.Noxt(, 18); Diagnostics session: 7 seconds (7.94 s selected) 36 37 3B doublc amount double.Parss(anountTextBox. Text) totalInserted anount; Events Picture one if (picturcone-) dProcess Memory IMB) 41 19 19 43 firstPictureBox. Inage Image.FromFile("Apple.bmp 45 else if (picture°ne# 1) CPU (% of all processors) 47 firstPicturcBox. Inage Image.FronFile("Banana.bmp) else it (pictureOne2) Exception Unhandled 50 51 firstPicturaBox. InageInage.FromFile("Cherries.bnp) Summary Events Memcry Usage CPU Usage 53 else if (pictureOne·3) Show Events (1 of 1) firstPictureBox. IaImage.FromFile"Grapes bmp Memory Usage View Details Copy Details 56 57 58 I clse if (picturcOnc4) Exccption Scttings Take Snapshot CPU Usage firstPictureBox. InageImage.FromFile"Lemon.bmp ● Record CPU Prohle 98% Lccals Excepticn Settings Waluc Banana.bmp nullj SingAjayProgramaForm1, Text: Slot Machine) Text "Spin" X 38 Y 29 Button Lett уре System.IO FileNotfo. Sirgh jayPrcgramo.. object (System.Win System.EventArgs ISCommon Languagtime Exceptions Break When ThroOW ConditioOnS this sender ■ C+ +Exceptions GPU Memory Access Exceptons JavaScript Runtme Exceptions Managed Debugging Assistants index pictureCne picturcTwo DWin32 Exceptions Walch 1 Exception Settings Immediale WindoW Add to Squrce Contral
Form 1.cs Form1.cs [Design] x Slot Machine Amount Inserted: Spin Exit 囤fruitsimageList
A slot machine is a gambling device into which the user inserts money and then pulls a lever (or presses a button). The slot machine then displays a set of random images. If two or more of the images match, the user wins an amount of money that the slot machine dispenses back to the user Create an application that simulates a slot machine. Figure shows an example of how the form should look. The application should let the user enter into a TextBox the amount of money he or she is inserting into the machine. When the user clicks the Spin button, the application should display three randomly selected symbols. (Slot machines traditionally display fruit symbols. You will find a set of fruit symbols in the ImageslFruit Symbols folder of the Student Sample Programs.) Figure Slot Machine application cation should let he user enter into a TexnBo the amount of money he or Slot Machine Amourt Ineerted S Spin If none of the randomly displayed images match, the program should inform the user that he or she has won SO. If two of the images match, the program should inform the user that he or she has won two times the amount entered. If three of the images match, the program should inform the user that he or she has won three times the amount entered. When the user clicks the Exit button to exit the application, the program should display the total amount of money entered into the slot machine and the total amount won.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

You are getting this error because you are not catching an unchecked expression in your code. The type of Exception is FileNotFoundException, this type of exception happens when the file you are trying to open is not found.

I would first suggest you to first make sure the file you are trying to exits actually exist.

And, moreover you would also need to catch the required exception as shown below.

try {

firstPictureBox.Image = Image.FromFile("Banana.bmp");

} catch(FileNotFoundException e) {

Console.WriteLine("Exception caught: {0}", e);

}

Add a comment
Know the answer?
Add Answer to:
C#: I am working on this application and keep running into this error. Please help me fix it. Err...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C# Temperature Converter Application: I have most of the application complete I just need only help...

    C# Temperature Converter Application: I have most of the application complete I just need only help with error messages. My instructor wants me to show four error messages inside an error message label (not a message box) and all of the error messages should appear inside error message label. The four error messages should appear when: 1: User enters data inside both Celsius and fahrenheit text boxes: “You should enter data in only one textbox. Press Clear to start over.”...

  • 6-1 Test and debug the Invoice Application i need help with this please.. all help is...

    6-1 Test and debug the Invoice Application i need help with this please.. all help is appreciated Source code Java: import java.util.Scanner; import java.text.NumberFormat; public class InvoiceApp { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String choice = "y"; while (!choice.equalsIgnoreCase("n")) { // get the input from the user System.out.print("Enter customer type (r/c): "); String customerType = sc.next(); System.out.print("Enter subtotal: "); double subtotal = sc.nextDouble(); // get the discount percent double discountPercent = 0.0; switch(customerType) {...

  • My Python file will not work below and I am not sure why, please help me...

    My Python file will not work below and I am not sure why, please help me debug! ********************************* Instructions for program: You’ll use these functions to put together a program that does the following: Gives the user sentences to type, until they type DONE and then the test is over. Counts the number of seconds from when the user begins to when the test is over. Counts and reports: The total number of words the user typed, and how many...

  • This is for a Unix class. Please help me out. I am attaching a skeletal code of the program below, it just needs ti be filled in. Below is a skeletal code of the program. Fork a child process...

    This is for a Unix class. Please help me out. I am attaching a skeletal code of the program below, it just needs ti be filled in. Below is a skeletal code of the program. Fork a child process and then use the parent for reading and the child for writing.  This is just a way of sending and receiving messages asynchronously. /* ************************************************************* * Utility functions * ************************************************************** */ static void usageError(const char * progName, const char *msg) {...

  • could you please help me with this problem, also I need a little text so I...

    could you please help me with this problem, also I need a little text so I can understand how you solved the problem? import java.io.File; import java.util.Scanner; /** * This program lists the files in a directory specified by * the user. The user is asked to type in a directory name. * If the name entered by the user is not a directory, a * message is printed and the program ends. */ public class DirectoryList { public static...

  • I need help with my very last assignment of this term PLEASE!!, and here are the instructions: After reading Chapter T...

    I need help with my very last assignment of this term PLEASE!!, and here are the instructions: After reading Chapter Two, “Keys to Successful IT Governance,” from Roger Kroft and Guy Scalzi’s book entitled, IT Governance in Hospitals and Health Systems, please refer to the following assignment instructions below. This chapter consists of interviews with executives identifying mistakes that are made when governing healthcare information technology (IT). The chapter is broken down into subheadings listing areas of importance to understand...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT