I am doing a calculator for figuring out the price of carpet per square yard. this is for a homework assignment. the assignment is as follows:
Create a Windows application for purchasing carpet.Allow the length and width of a
room to be entered. Have a control that displays different prices of carpet. Include, for
example, prices such as $21.95 per square yard.After the users enter their room dimensions
and the price of the carpet, display the total cost to carpet the room. Include an
option to clear selections.
according to the instructions i need a control that displays the different prices of carpet. now i have that figured as a control box. I'm in college learning to become a programmer. the problem is i can get everything to work in the window with the exception of getting the price to calculate into the equation. any help i can get to help me solve this would be appriciated.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace CarpetCalc
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Calculate_Click(object sender, EventArgs e)
{
double rmlength = 0;
double rmwidth = 0;
double pricePerYard = 0;
double totalCost = 0;
/* Calculating Price Per Yard
Formula Used: length * Width / 9 = sq yd
*/
rmlength = Convert.ToDouble(roomLength.Text);
rmwidth = Convert.ToDouble(roomWidth.Text);
pricePerYard = Decimal.Parse(PriceYd.SelectedItem.ToString());
totalCost = (rmlength * rmwidth) / 9;
TotalCstTxt.Text = totalCost.ToString("N2");
}
private void Reset_Click(object sender, EventArgs e)
{
// This is used to clear the box when you hit reset
roomLength.Clear();
roomWidth.Clear();
TotalCstTxt.Clear();
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
namespace CarpetCalc
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.Calculate = new System.Windows.Forms.Button();
this.Reset = new System.Windows.Forms.Button();
this.roomWidth = new System.Windows.Forms.TextBox();
this.roomLength = new System.Windows.Forms.TextBox();
this.TotalCstTxt = new System.Windows.Forms.TextBox();
this.PriceYd = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("MS Reference Sans Serif", 14F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label1.ForeColor = System.Drawing.Color.Yellow;
this.label1.Location = new System.Drawing.Point(51, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(175, 24);
this.label1.TabIndex = 0;
this.label1.Text = "Carpet Calculator";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Font = new System.Drawing.Font("MS Reference Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label2.ForeColor = System.Drawing.Color.Yellow;
this.label2.Location = new System.Drawing.Point(12, 66);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(117, 16);
this.label2.TabIndex = 1;
this.label2.Text = "Length of Room:";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Font = new System.Drawing.Font("MS Reference Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label3.ForeColor = System.Drawing.Color.Yellow;
this.label3.Location = new System.Drawing.Point(16, 103);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(110, 16);
this.label3.TabIndex = 2;
this.label3.Text = "Width of Room:";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Font = new System.Drawing.Font("MS Reference Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label4.ForeColor = System.Drawing.Color.Yellow;
this.label4.Location = new System.Drawing.Point(21, 213);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(94, 20);
this.label4.TabIndex = 3;
this.label4.Text = "Total Cost";
//
// label5
//
this.label5.AutoSize = true;
this.label5.Font = new System.Drawing.Font("MS Reference Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label5.ForeColor = System.Drawing.Color.Yellow;
this.label5.Location = new System.Drawing.Point(19, 136);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(107, 16);
this.label5.TabIndex = 4;
this.label5.Text = "Price per Yard:";
//
// Calculate
//
this.Calculate.Font = new System.Drawing.Font("MS Reference Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.Calculate.Location = new System.Drawing.Point(44, 272);
this.Calculate.Name = "Calculate";
this.Calculate.Size = new System.Drawing.Size(93, 31);
this.Calculate.TabIndex = 5;
this.Calculate.Text = "Calculate ";
this.Calculate.UseVisualStyleBackColor = true;
this.Calculate.Click += new System.EventHandler(this.Calculate_Click);
//
// Reset
//
this.Reset.Font = new System.Drawing.Font("MS Reference Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.Reset.Location = new System.Drawing.Point(169, 272);
this.Reset.Name = "Reset";
this.Reset.Size = new System.Drawing.Size(74, 31);
this.Reset.TabIndex = 6;
this.Reset.Text = "Reset";
this.Reset.UseVisualStyleBackColor = true;
this.Reset.Click += new System.EventHandler(this.Reset_Click);
//
// roomWidth
//
this.roomWidth.Location = new System.Drawing.Point(135, 102);
this.roomWidth.Name = "roomWidth";
this.roomWidth.Size = new System.Drawing.Size(128, 20);
this.roomWidth.TabIndex = 2;
//
// roomLength
//
this.roomLength.Location = new System.Drawing.Point(135, 65);
this.roomLength.Name = "roomLength";
this.roomLength.Size = new System.Drawing.Size(128, 20);
this.roomLength.TabIndex = 1;
//
// TotalCstTxt
//
this.TotalCstTxt.Location = new System.Drawing.Point(135, 213);
this.TotalCstTxt.Name = "TotalCstTxt";
this.TotalCstTxt.Size = new System.Drawing.Size(128, 20);
this.TotalCstTxt.TabIndex = 4;
//
// PriceYd
//
this.PriceYd.FormattingEnabled = true;
this.PriceYd.Items.AddRange(new object[] {
"$1.60",
"$2.50",
"$3.25",
"$4.50"});
this.PriceYd.Location = new System.Drawing.Point(135, 135);
this.PriceYd.Name = "PriceYd";
this.PriceYd.Size = new System.Drawing.Size(121, 21);
this.PriceYd.TabIndex = 3;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.Navy;
this.ClientSize = new System.Drawing.Size(287, 315);
this.Controls.Add(this.PriceYd);
this.Controls.Add(this.TotalCstTxt);
this.Controls.Add(this.roomLength);
this.Controls.Add(this.roomWidth);
this.Controls.Add(this.Reset);
this.Controls.Add(this.Calculate);
this.Controls.Add(this.label5);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "Carpet Calculator";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Button Calculate;
private System.Windows.Forms.Button Reset;
private System.Windows.Forms.TextBox roomWidth;
private System.Windows.Forms.TextBox roomLength;
private System.Windows.Forms.TextBox TotalCstTxt;
private System.Windows.Forms.ComboBox PriceYd;
}
}