1

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

Question

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

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.

Answers

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);

}


Similar Solved Questions

2 answers
Sally wants a new bicycle, but her mother and father will not buy her one
Sally wants a new bicycle, but her mother and father will not buy her one. correct punctuation...
8 answers
Determine which arguments are valid 2
determine which arguments are valid 2. The Lakers almost didn’t beat the Kings. They’ll never get past Dallas. 3. If the butler had done it, he could not have locked the screen door. Therefore, since the door was locked, we know that the butler is in the clear. 5. Hey, he can’t be ...
1 answers
Question 18 (3 points) In a standing wave, not necessarily at the fundamental frequency, on a...
Question 18 (3 points) In a standing wave, not necessarily at the fundamental frequency, on a string of length L, what is the distance between two nodes? 1/4 ON2 2 O 1/4 OL42...
1 answers
During an experimental workup you determine that k2 = 1200 s-1 . When you set [ET]...
During an experimental workup you determine that k2 = 1200 s-1 . When you set [ET] = 10 nM and [S] = 40 μM, you observe Vo progressing at 9.6 μM s-1 . For this reaction, what is KM?...
1 answers
Module For operating cash flow I used net income + depreciation but my professor states that...
Module For operating cash flow I used net income + depreciation but my professor states that is the wrong answer. Is there another way to calculate operating cost? If so can you please show me and explain? Thank you Sales            ...
1 answers
The magnetic field in a region is given by B = (0.750 +0.350) T. At some...
The magnetic field in a region is given by B = (0.750 +0.350) T. At some instant, a particle with charge q = 26.0 mc has velocity v = (35.69 + 107.3 + 38.5) m/s. What is the magnetic force exerted on the particle at that instant? (Express your answer in vector form.) N...
1 answers
Describe in three sentences the action of mydriqtics in what circumstances this type of deugs would...
describe in three sentences the action of mydriqtics in what circumstances this type of deugs would be use...
1 answers
Assume the following information regarding U.S. and British currency values and 1-year rates: Spot Rate $1...
Assume the following information regarding U.S. and British currency values and 1-year rates: Spot Rate $1 = £0.8299 1-Year Forward Rate $1 = £0.8631 British 1-Year Interest Rate 7.0% U.S. 1-Year Interest Rate 5.0% Given this information, what is the yield (or profits) to a British inves...
1 answers
What is the relationship between the pH of water, vinegar, and ammonia?
What is the relationship between the pH of water, vinegar, and ammonia?...
1 answers
What crops were discovered that could replenish the nutrients of the soil?
What crops were discovered that could replenish the nutrients of the soil?...
1 answers
Consider 1-2 Vr? + y + 3 LLL da dydar. V1-38-98 V +y + y2 +22...
Consider 1-2 Vr? + y + 3 LLL da dydar. V1-38-98 V +y + y2 +22 +y +22-2 the origin to the point (2, y, ) makes with the z-axis is a new angle which we will label o, and we label the length of the line segment p. We can now determine the remaining side-lengths of our new triangle. Let us try to label ...
1 answers
Where does all the water go? According to the Environmental Protection Agency (EPA), in a typical...
Where does all the water go? According to the Environmental Protection Agency (EPA), in a typical wetland environment, 39% of the water is outflow; 49% is seepage; 5% evaporates; and 7% remains as water volume in the ecosystem (Reference: United States Environmental Protection Agency Case Studies Re...
1 answers
A fisherman notices that his boat is moving up and down periodically without any horizontal motion,...
A fisherman notices that his boat is moving up and down periodically without any horizontal motion, owing to waves on the surface of the water. It takes a time of 3.00 s for the boat to travel from its highest point to its lowest, a total distance of 0.630 m . The fisherman sees that the wave crests...
1 answers
Let (di, d2,... .dk) (w1, w2,..., wx)-0 (mod n) be an error detection scheme for the...
Let (di, d2,... .dk) (w1, w2,..., wx)-0 (mod n) be an error detection scheme for the k-digit identification number did2 . . .dk, where 0 〈 di 〈 n. Prove that all transposition errors of two digits di and dj are detected if and only if gcd(ui-y,n) = 1 for i and j between 1 and k...

-- 0.017785--