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

I need help with a C# Assignment which i constructed: my issue is that i cannot

ID: 3689557 • Letter: I

Question

I need help with a C# Assignment which i constructed: my issue is that i cannot get the buttons in my form to reset all text or calculate. the form itself is simple. it is a miles to gallon calculator to determine a trip's gas. below ill paste the assignment as well as my code and a screenshot of my output. once again the only issue im having is getting the buttons to do what they need to do...

ASSIGNMENT: Create a Trip Calculator Windows application that can be used to determine miles per gallon for a given trip. Set the Form object properties of Name, ForeColor, BackColor, Size, Location, Text, and AcceptButton. The form should contain labels and textboxes to allow the user to input trip destination, miles traveled, and gallons of gas consumed. Two buttons should be placed on the form. Name all objects used in program statements. When the user clicks the button that performs the calculations, display a in a label the miles per gallon for that trip. The output is supposed to be displayed in label4.

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

private void Form1_Load(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{
double m, g, c;

m = Convert.ToDouble(textBox2.Text);
g = Convert.ToDouble(textBox3.Text);

c = m / g;

label4.Text = "Miles per Gallon: " + c;

}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();

}
}
}

Miles From Gallons Caculator- Trip Destination bahamas Miles Traveled: Miles Traveled 12000 Gallons of Gas Used 15000 Caculate Reset label4

Explanation / Answer

Inititalise the buttons and textboxes ... code added ..check

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 gallon_to_miles
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.textBoxTrip = new System.Windows.Forms.TextBox();
this.textBoxMiles = new System.Windows.Forms.TextBox();
this.textBoxGallons = new System.Windows.Forms.TextBox();
this.calculate = new System.Windows.Forms.Button();
this.Reset = new System.Windows.Forms.Button();
this.label4 = new System.Windows.Forms.Label();
this.SuspendLayout();

// textBoxTrip
this.textBoxTrip.Name = "Trip Destination";
this.textBoxTrip.TabIndex = 1;
this.textBoxTrip.Text = "";

// textBoxTrip
this.textBoxMiles.Name = "Miles Travelled";
this.textBoxMiles.TabIndex = 1;
this.textBoxMiles.Text = "";

// textBoxTrip
this.textBoxGallons.Name = "Gallons of Gas Used";
this.textBoxGallons.TabIndex = 1;
this.textBoxGallons.Text = "";

// calculate button
this.calculate.Name = "Calculate";
this.calculate.TabIndex = 2;
this.calculate.Text = "calculate";
this.calculate.Click += new System.EventHandler(this.button1_Click);
this.calculate.MouseEnter += new System.EventHandler(this.Buttons_OnMouseEnter);
this.calculate.MouseLeave += new System.EventHandler(this.Buttons_OnMouseLeave);

// calculate button
this.Reset.Name = "Reset";
this.Reset.TabIndex = 2;
this.Reset.Text = "Reset";
this.Reset.Click += new System.EventHandler(this.button2_Click);
this.Reset.MouseEnter += new System.EventHandler(this.Buttons_OnMouseEnter);
this.Reset.MouseLeave += new System.EventHandler(this.Buttons_OnMouseLeave);


this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.textBoxTrip,
this.Miles,
this.Gallons,
this.calculate,
this.Reset,
this.label4});
this.Name = "MilesFromGallonsCalculator";
this.Text = "Miles From Gallons Calculator";
this.ResumeLayout(false);

}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
double m, g, c;
m = Convert.ToDouble(textBox2.Text);
g = Convert.ToDouble(textBox3.Text);
c = m / g;
label4.Text = "Miles per Gallon: " + c;
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote